fork(2) download
  1. #include <bits/stdc++.h>
  2. #define int long long
  3. using namespace std;
  4. pair<int, int> a[10001];
  5. int n, m, r = 0, l = 0, k = 0,res;
  6. bool cmp(pair<int, int> v, pair<int, int> t) {
  7. return v.first < t.first;
  8. }
  9. signed main() {
  10. cin >> n >> m;
  11. for (int i = 1; i <= n; i++) {
  12. cin >> a[i].first;
  13. a[i].second = i;
  14. }
  15. sort(a + 1, a + n + 1, cmp);
  16. for (int i = 1; i <= n - 1; i++) {
  17. for (int j = i + 1; j <= n; j++) {
  18. int ans = m - a[i].first - a[j].first;
  19. if (ans < 0) break;
  20. int lo = 1 , hi = n;
  21. while (lo <= hi) {
  22. int mid = (lo + hi) / 2;
  23. if (a[mid].first <= ans) {
  24. lo = mid + 1;
  25. res=mid;
  26. }
  27. else {
  28. hi = mid - 1;
  29. }
  30. }
  31. if (a[res].first==ans&&a[res].second!=a[i].second&&a[res].second!=a[j].second)
  32. {
  33. l=a[i].second;
  34. r=a[j].second;
  35. k=a[res].second;
  36. cout<<l<<" "<<r<<" "<<k;
  37. return 0;
  38. }
  39. }
  40. }
  41. if (l == 0) {
  42. cout << "IMPOSSIBLE";
  43. }
  44. return 0;
  45. }
Success #stdin #stdout 0.01s 5300KB
stdin
4 8
2 7 5 1
stdout
4 1 3