Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <set>
- #include <vector>
- using namespace std;
- multiset<pair<int, int> > all;
- pair<int, int> solve(vector<int> &a, int S) {
- for (int i = 0; i < a.size(); i++) {
- auto pos = all.lower_bound({S - a[i], 0});
- if (pos != all.end() && pos -> first == S - a[i])
- return make_pair(pos -> second, i);
- all.insert({a[i], i});
- }
- return make_pair(-1, -1);
- }
- int main()
- {
- int n, S;
- vector<int> a;
- cin >> n >> S;
- a.resize(n);
- for (int i = 0; i < n; i++)
- cin >> a[i];
- pair<int, int> ans = solve(a, S);
- if (ans.first == -1)
- cout << "No such pairs";
- else
- cout << ans.first << ' ' << ans.second;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement