hulabitetmung
NguyenAnhQuan
c_cpp
a year ago
1.3 kB
4
Indexable
#include <iostream> #include <vector> #include <algorithm> #include <math.h> #include <map> #define LIM 1005 #define ll long long using namespace std; typedef pair<int, int> pii; int n, X; int a[LIM]; map <int, vector<pii>> sum; vector <int> ans; void Process() { for (int i = 1; i < n; i++) { for (int j = 0; j < i; j++) { int cursum = a[i] + a[j]; int expect = X - cursum; if (sum.count(expect) > 0) { for (auto k : sum[expect]) { if (k.first != i && k.first != j && k.second != i && k.second != j) { ans.push_back(i); ans.push_back(j); ans.push_back(k.first); ans.push_back(k.second); return; } } } sum[cursum].push_back({i, j}); } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> X; for (int i = 0; i < n; i++) cin >> a[i]; Process(); if (ans.size() > 0) { sort(ans.begin(), ans.end()); for (auto i : ans) cout << i + 1 << " "; } else { cout << "IMPOSSIBLE"; } return 0; }
Editor is loading...
Leave a Comment