another 4 sorting and searching problems

This commit is contained in:
2024-06-04 11:04:33 +02:00
parent 4e39870547
commit 7fd24571df
5 changed files with 106 additions and 1 deletions

View File

@@ -0,0 +1,33 @@
// Sum of Two Values
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
map<ll, vector<int>> input;
int n; cin >> n;
ll x; cin >> x;
vector<ll> in;
for (int i{}; i < n; i++) {
ll a; cin >> a;
input[a].push_back(i);
in.push_back(a);
}
for (int i{}; i < n; i++) {
ll target = x - in[i];
bool flag = target == in[i];
if (input[target].empty() || (input[target].size() == 1 && flag)) continue;
else {
if (flag) {
cout << i + 1 << " " << input[target][1] + 1<< endl;
} else {
cout << i + 1 << " " << input[target][0] + 1<< endl;
}
return 0;
}
}
cout << "IMPOSSIBLE" << endl;
return 0;
}