fork download
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4.  
  5. using namespace std;
  6. using namespace __gnu_pbds;
  7. using ll = long long;
  8. using ld = long double;
  9.  
  10. #define all(x) x.begin(),x.end()
  11. #define v(x) vector<x>
  12. #define nl '\n'
  13. #define fxd(x) fixed << setprecision(x)
  14. template<class t> using ordered_set = tree<t, null_type, less<t>, rb_tree_tag, tree_order_statistics_node_update>;
  15. template<class t> using ordered_multiset = tree<t, null_type, less_equal<t>, rb_tree_tag, tree_order_statistics_node_update>;
  16.  
  17.  
  18. int main()
  19. {
  20. ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  21. ll n , t; cin >> n >> t;
  22. // val,pos
  23. vector<pair<ll,ll>> arr(n);
  24. for (int i = 0; i < n; i++)
  25. {
  26. cin >> arr[i].first;
  27. arr[i].second = i+1;
  28. }
  29.  
  30. sort(all(arr));
  31.  
  32. ll l = 0, r = n-1;
  33. while (l < r)
  34. {
  35. if(arr[l].first+arr[r].first == t)
  36. {
  37. cout << arr[l].second << " " << arr[r].second;
  38. return 0;
  39. }
  40. else if(arr[l].first+arr[r].first > t)
  41. {
  42. r--;
  43. }
  44. else
  45. {
  46. l++;
  47. }
  48. }
  49. cout << "IMPOSSIBLE";
  50.  
  51. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
IMPOSSIBLE