fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. inline int power(int a, int b) {
  6. int x = 1;
  7. while (b) {
  8. if (b & 1) x *= a;
  9. a *= a;
  10. b >>= 1;
  11. }
  12. return x;
  13. }
  14.  
  15.  
  16. const int M = 1000000007;
  17. const int N = 3e5+9;
  18. const int INF = 2e9+1;
  19. const int LINF = 2000000000000000001;
  20.  
  21. //_ ***************************** START Below *******************************
  22.  
  23.  
  24. //* Guranteed only 1 soln exists, return index of pair x,y
  25. vector<int> a;
  26. void consistency(int n, int k) {
  27.  
  28. vector<pair<int,int>> b;
  29. for(int i=0; i<n; i++){
  30. b.push_back({a[i], i});
  31. }
  32. sort(begin(b), end(b));
  33. int i = 0, j = n-1;
  34.  
  35. while(i<=j){
  36. int sum = b[i].first + b[j].first;
  37. if(sum < k){
  38. i++;
  39. }
  40. else if(sum > k){
  41. j--;
  42. }
  43. else {
  44. cout << b[i].second << " , " << b[j].second << endl;
  45. break;
  46. }
  47. }
  48.  
  49. }
  50.  
  51.  
  52. void solve() {
  53.  
  54. int n, k;
  55. cin >> n >> k ;
  56. a.resize(n);
  57. for(int i=0; i<n; i++) cin >> a[i];
  58.  
  59. consistency(n, k);
  60.  
  61. }
  62.  
  63.  
  64.  
  65.  
  66.  
  67. int32_t main() {
  68. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  69.  
  70. int t = 1;
  71. // cin >> t;
  72. while (t--) {
  73. solve();
  74. }
  75.  
  76. return 0;
  77. }
Success #stdin #stdout 0.01s 5284KB
stdin
4 9
2 7 11 15
stdout
0 , 1