Sample Input 1:
8 15
1 2 8 7 2 4 11 15
Sample Output 1:
4 11
Sample Input 2:
7 14
1 8 7 2 4 11 15
Sample Output 2:
No Solution
idea
- 测试点1:m比i小的情况处理
- 小细节:i == m/2时,注意i的出现次数必须大于一次
solution
#include <stdio.h>
int main(){
int n, m, d, hash[501] = {0};
scanf("%d%d", &n, &m);
for(int i = 0; i < n; i++){
scanf("%d", &d);
hash[d]++;
}
for(int i = 1; i < 501; i++){
if(hash[i] && m > i && m - i <= 500){
hash[i]--;
if(hash[m-i]) {
printf("%d %d", i, m - i);
return 0;
}
}
}
printf("No Solution");
return 0;
}