another 4 sorting and searching problems
This commit is contained in:
33
CSES - CSES Problem Set/Sum_of_Two_Values.cpp
Normal file
33
CSES - CSES Problem Set/Sum_of_Two_Values.cpp
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user