fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ms(s,n) memset(s,n,sizeof(s))
  5. #define all(a) a.begin(),a.end()
  6. #define present(t, x) (t.find(x) != t.end())
  7. #define sz(a) int((a).size())
  8. #define FOR(i, a, b) for (int i = (a); i < (b); ++i)
  9. #define FORd(i, a, b) for (int i = (a) - 1; i >= (b); --i)
  10. #define pb push_back
  11. #define pf push_front
  12. #define fi first
  13. #define se second
  14. #define mp make_pair
  15.  
  16. typedef long long ll;
  17. typedef unsigned long long ull;
  18. typedef long double ld;
  19. typedef pair<int,int> pi;
  20. typedef vector<int> vi;
  21. typedef vector<pi> vii;
  22.  
  23. const int MOD = (int) 1e9+7;
  24. const int INF = (int) 1e9+1;
  25. inline ll gcd(ll a,ll b){ll r;while(b){r=a%b;a=b;b=r;}return a;}
  26. inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
  27.  
  28. int bs(pi a[], int l, int r, int x){
  29. while(l <= r){
  30. int m = (l + r) / 2;
  31. if(a[m].fi == x){
  32. return a[m].se;
  33. }
  34. else if (a[m].fi < x) l = m + 1;
  35. else r = m - 1;
  36. }
  37. return -1;
  38. }
  39.  
  40. int main(){
  41. #ifndef ONLINE_JUDGE
  42. freopen("input.txt", "r", stdin);
  43. freopen("output.txt", "w", stdout);
  44. #endif
  45. int n, x; cin >> n >> x;
  46. pi a[n];
  47. for(int i = 0; i < n; i++){
  48. cin >> a[i].fi;
  49. a[i].se = i;
  50. }
  51. //O(n*nlogn)
  52. sort(a, a + n);
  53. for(int i = 0; i < n - 2; i++){
  54. int l = i +1, r = n - 1;
  55. int y = x - a[i].fi;
  56. while(l < r){
  57. if(a[l].fi + a[r].fi == y){
  58. cout << a[i].se + 1 << " " << a[l].se + 1 <<" " << a[r].se + 1 << endl;
  59. return 0;
  60. }
  61. else if (a[l].fi + a[r].fi < y){
  62. ++l;
  63. }
  64. else --r;
  65. }
  66. }
  67. cout << "IMPOSSIBLE\n";
  68. return 0;
  69. }
Runtime error #stdin #stdout 0.66s 2095944KB
stdin
Standard input is empty
stdout
Standard output is empty