Advertisement
MaxObznyi

Q.14

Nov 17th, 2019
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. multiset<pair<int, int> > all;
  7.  
  8. pair<int, int> solve(vector<int> &a, int S) {
  9. for (int i = 0; i < a.size(); i++) {
  10. auto pos = all.lower_bound({S - a[i], 0});
  11. if (pos != all.end() && pos -> first == S - a[i])
  12. return make_pair(pos -> second, i);
  13. all.insert({a[i], i});
  14. }
  15. return make_pair(-1, -1);
  16. }
  17.  
  18. int main()
  19. {
  20. int n, S;
  21. vector<int> a;
  22. cin >> n >> S;
  23. a.resize(n);
  24. for (int i = 0; i < n; i++)
  25. cin >> a[i];
  26. pair<int, int> ans = solve(a, S);
  27. if (ans.first == -1)
  28. cout << "No such pairs";
  29. else
  30. cout << ans.first << ' ' << ans.second;
  31. return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement