题目链接:
https://pintia.cn/problem-sets/994805342720868352/problems/994805432256675840
思路:用一个数组保存每个数有没有出现过,遍历一遍就可以得到答案。
代码:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5 , INF = 0x7f7f7f7f;
int vis[maxn];
int main() {
int n , m;
ios::sync_with_stdio(0);
cin >> n >> m;
int ans = INF;
for(int i = 0 ; i < n ; i++) {
int t;
cin >> t;
int t1 = m - t;
if(t1 > 0) {
if(vis[t1]) {
ans = min(ans , min(t , t1));
}
}
vis[t] = 1;
}
if(ans < INF) {
cout << ans << " " << m - ans << "\n";
}
else cout << "No Solution\n";
return 0;
}