fork download
  1. #include <bits/stdc++.h>
  2.  
  3. #define fst first
  4. #define snd second
  5.  
  6. using namespace std;
  7.  
  8. typedef long long ll;
  9. typedef pair<int, int> ii;
  10.  
  11. const int INF = 1e9;
  12. const ll LINF = 1e18;
  13.  
  14. const int N = 5e3 + 5;
  15.  
  16. int n, x;
  17. ii a[N];
  18.  
  19. int main() {
  20. ios::sync_with_stdio(false);
  21. cin.tie(nullptr);
  22. cin >> n >> x;
  23. for (int i = 1; i <= n; i++) {
  24. cin >> a[i].fst;
  25. a[i].snd = i;
  26. }
  27.  
  28. sort(a + 1, a + n + 1);
  29.  
  30. for (int i = 1; i <= n; i++) {
  31. for (int j = i + 1, k = n + 1; j <= n; j++) {
  32. // i < j < k
  33. // k là vị trí nhỏ nhất thoả mãn a[k] >= x - a[i] - a[j]
  34. while (k - 1 > j && a[k - 1].fst >= (x - a[i].fst) - a[j].fst) k--;
  35. if (!(j < k && k <= n)) continue;
  36. if (a[i].fst + a[j].fst + a[k].fst == x) {
  37. cout << a[i].snd << ' ' << a[j].snd << ' ' << a[k].snd << '\n';
  38. return 0;
  39. }
  40. }
  41. }
  42.  
  43. cout << "IMPOSSIBLE" << '\n';
  44. }
Success #stdin #stdout 0s 5284KB
stdin
4 8
2 7 5 1
stdout
4 1 3