Submission
Status:
PPP-PPPP-P
Subtask/Task Score:
80/100
Score: 80
User: nemuchannnUwU
Problemset: จับคู่เลขมงคล
Language: cpp
Time: 0.002 second
Submitted On: 2025-10-15 12:01:33
#include<bits/stdc++.h>
using namespace std;
int main(){
cin.tie(nullptr)->sync_with_stdio(0);
int n;
cin >> n;
vector<pair<int,int>> v(n);
for (int i=0;i<n;i++){
cin >> v[i].first;
v[i].second=i;
}
sort(v.begin(),v.end());
int target; cin >> target;
int l=0,r=n-1;
bool find=false;
while(l<r){
int sum=v[l].first+v[r].first;
if (sum==target){
if (v[l].second<v[r].second) cout << v[l].first << " " << v[r].first << "\n";
else cout << v[r].first << " " << v[l].first << "\n";
find=true;
l++;
r--;
}
else if(sum>target) r--;
else l++;
}
if (!find) cout << "No";
}