水题,详见代码~
#include <iostream> #include <string.h> #include <cstdio> #include <algorithm> #include <cstdlib> #include <math.h> #include <queue> #include <stack> #include <vector> #include <unordered_map> #define maxn 100005 #define INF 0x3f3f3f3f using namespace std; typedef long long ll; int n,m; int x[maxn],vis[maxn]; int main() {memset(vis,0,sizeof(vis));scanf("%d %d",&n,&m);for(int i=0;i<n;i++){scanf("%d",&x[i]);vis[x[i]]++;}sort(x,x+n);for(int i=0;i<n;i++){if(vis[m-x[i]]){if(m-x[i]==x[i]&&vis[x[i]]>=2){printf("%d %d\n",x[i],x[i]);return 0;}else if(m-x[i]!=x[i]){printf("%d %d\n",x[i],m-x[i]);return 0;}}}cout<<"No Solution"<<endl;return 0; }