Submission
Status:
PPP--PPP--
Subtask/Task Score:
60/100
Score: 60
User: Bestzu
Problemset: จับคู่เลขมงคล
Language: cpp
Time: 0.004 second
Submitted On: 2025-10-14 10:25:00
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n; cin >> n;
vector<int> a(n);
for(int i = 0; i < n; i++) {
cin >> a[i];
}
int target; cin >> target;
sort(a.begin(), a.end());
int l = 0, r = n-1;
bool found = false;
while(l < r) {
if(a[l] + a[r] == target) {
cout << a[r] << " " << a[l] << endl;
l++; r--;
found = true;
}
else if(a[l] + a[r] > target) {
r--;
}
else {
l++;
}
}
if(!found) cout << "No";
return 0;
}