1048 Find Coins (25 point(s))

题解

题意不难,主要时间限制150ms,所以尽量限制时间复杂度。还好没有限制空间条件很严。所以用下标标记法标记。。。

#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
const int MAXN = 510;
const int MAXM = 1e5 + 10;
int book[MAXN], t[MAXM];
int n, m;
int main() {
	scanf("%d%d", &n, &m);
	for(int i = 0; i < n; ++i) {
		scanf("%d", &t[i]);
		++book[t[i]];
	}
	sort(t, t + n);
	int i;
	for(i = 0; i < n; ++i) {
		--book[t[i]];
		if(book[m - t[i]]) break;
	}	
	if(i == n) printf("No Solution\n");
	else printf("%d %d\n", t[i], m - t[i]);
	return 0;
}

 

相关文章:

  • 2021-06-04
  • 2021-07-06
  • 2021-10-02
  • 2021-07-13
  • 2021-12-09
  • 2021-06-21
  • 2022-03-01
  • 2022-03-05
猜你喜欢
  • 2021-11-15
  • 2022-12-23
  • 2022-12-23
  • 2021-05-31
  • 2021-04-09
  • 2022-12-23
  • 2021-04-23
相关资源
相似解决方案