fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. // #define int long long int
  5. #define ld long double
  6. #define all(x) x.begin(), x.end()
  7. #define sortall(x) sort(all(x))
  8. #define endl '\n'
  9. #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  10. template<class T>
  11. void printC (T Collection)
  12. {
  13. for (auto&i:Collection)
  14. cout << i << " \n";
  15. cout << '\n';
  16. }
  17.  
  18. /*
  19.  * Think twice, code once
  20.  * Think of different approaches to tackle a problem: write them down.
  21.  * Think of different views of the problem. don't look from only one side.
  22.  * don't get stuck in one approach.
  23.  * common mistakes: - over_flow
  24.  * - out_of_bound index
  25.  * - infinite loop
  26.  * - corner cases
  27.  * - duplication counting.
  28. */
  29.  
  30. void solve()
  31. {
  32. int n, x; cin >> n >> x;
  33. vector<int> v(n);
  34. map<int, pair<int, int>> pos;
  35. for (int i = 0; i < v.size(); ++i)
  36. {
  37. cin >> v[i];
  38. if (pos[v[i]].first == 0)
  39. pos[v[i]].first = i+1;
  40. else
  41. pos[v[i]].second = i+1;
  42. }
  43. sort(all(v));
  44. int l = 0, r = v.size()-1;
  45. while (l < r)
  46. {
  47. if (v[l] + v[r] == x)
  48. {
  49. if (pos[v[l]].first != pos[v[r]].first)
  50. cout << pos[v[l]].first << ' ' << pos[v[r]].first;
  51. else
  52. cout << pos[v[l]].first << ' ' << pos[v[r]].second;
  53. return;
  54. }else if (v[l] + v[r] < x)
  55. l++;
  56. else
  57. r--;
  58. }
  59. cout << "IMPOSSIBLE";
  60. }
  61.  
  62. int32_t main()
  63. {
  64. // #ifndef ONLINE_JUDGE
  65. // freopen("input.txt", "r", stdin);
  66. // freopen("output.txt", "w", stdout);
  67. // freopen("Errors.txt", "w", stderr);
  68. // #endif
  69. fast
  70. int t = 1;
  71. // cin >> t;
  72. while (t--)
  73. {
  74. solve();
  75. if (t) cout << '\n';
  76. }
  77. cout << '\n';
  78. return 0;
  79. }
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
IMPOSSIBLE