# | User | Rating |
---|---|---|
1 | tourist | 3845 |
2 | jiangly | 3707 |
3 | Benq | 3630 |
4 | orzdevinwang | 3573 |
5 | Geothermal | 3569 |
5 | cnnfls_csy | 3569 |
7 | jqdai0815 | 3532 |
8 | ecnerwala | 3501 |
9 | gyh20 | 3447 |
10 | Rebelz | 3409 |
# | User | Contrib. |
---|---|---|
1 | maomao90 | 171 |
2 | adamant | 163 |
2 | awoo | 163 |
4 | TheScrasse | 154 |
5 | nor | 153 |
6 | maroonrk | 152 |
6 | -is-this-fft- | 152 |
8 | Petr | 145 |
9 | pajenegod | 144 |
9 | orz | 144 |
Name |
---|
i solved it much easier, checking all possible sums of two ellements, from
i + 1 to n - 1
,and after it check do i have a
k - sum_of_two_ellemnts
, if yes, it's our answer, else we're putting tomap
all possible sums of two ellements, from0 to i
. Its' all what i was need to solve this problemcan you find error in my code ??
Your idea it's wrong, you're doing somethink like greedy not 2pointer. But perhap i didn't get your idea well
void solve() { int n, x; cin >> n >> x; vectorsol(n); for(auto &i : sol) cin >> i; map<int,pair<int,int>>mvp; for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { if(i == j) continue; mvp[sol[i] + sol[j]] = {i, j}; } } for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { if(i == j) continue; int sm = sol[i] + sol[j]; int rem = x — sm; if(mvp.find(rem) != mvp.end()) { auto pp = mvp[rem]; setst; st.insert(i); st.insert(j); st.insert(pp.first); st.insert(pp.second); if(st.size() == 4) { for(auto k : st) cout << k + 1 << ' '; return; } } } } cout << "IMPOSSIBLE";
}