fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4. #include <algorithm>
  5. #include <bits/stdc++.h>
  6. #include <set>
  7. #include <ext/pb_ds/assoc_container.hpp>
  8. #include <ext/pb_ds/tree_policy.hpp>
  9. #include <map>
  10. #define ll long long
  11. using namespace __gnu_pbds;
  12. using namespace std;
  13. template <class T>
  14. using ordered_set = tree<T , null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update>;
  15. template <class T>
  16. using ordered_set1 = tree<T , null_type , greater<T> , rb_tree_tag , tree_order_statistics_node_update>;
  17. // less<T>/greater<T> = ascending/descending.
  18. // less_equal<>/greater_equal<> for ordered multiset
  19. // ordered_multiset note : s.find(), s.erase() don't work + s.upper_bound() and s.lower_bound() swap jobs;
  20. void fastIO(void) {
  21. ios_base::sync_with_stdio(false);
  22. cin.tie(NULL);
  23. cout.tie(NULL);
  24. }
  25. int main() {
  26. fastIO();
  27. ll n,sum; cin>>n>>sum;
  28. vector<ll> v(n);
  29. vector<ll> v2(n);
  30. for (ll i = 0; i<n; i++) {
  31. cin>>v[i];
  32. v2[i]=v[i];
  33. }
  34. sort(v.begin(),v.end());
  35. ll l=0,r=n-1; bool flag = 0;
  36.  
  37. while (l<r) {
  38. if (v[l]+v[r]>sum) {
  39. r--;
  40. }
  41. else if (v[l]+v[r]<sum) {
  42. l++;
  43. }
  44. else {
  45. flag = 1;
  46. break;
  47. }
  48. }
  49.  
  50. if (flag) {
  51. ll realL,realR;
  52. for (ll i = 0; i<n; i++) {
  53. if (v2[i]==v[l]) {
  54. realL=i;
  55. break;
  56. }
  57. }
  58. for (ll i = 0; i<n; i++) {
  59. if (v2[i]==v[r]) {
  60. realR=i;
  61. break;
  62. }
  63. }
  64. cout<<realL+1<<' '<<realR+1;
  65. }
  66. else {
  67. cout<<"IMPOSSIBLE";
  68. }
  69. }
Success #stdin #stdout 0.01s 5280KB
stdin
4 8
2 7 5 1
stdout
4 2