fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5. int main() {
  6. int n,x;cin>>n>>x;
  7. vector<pair<int,int>>v;
  8. for(int i =0;i<n;i++){
  9. int x;cin>>x;
  10. v.push_back({x,i+1});
  11. }
  12. sort(v.begin(),v.end());
  13. int l=0,r=n-1;
  14. while(l<r){
  15. if(v[l].first+v[r].first>x) r--;
  16. else if(v[l].first+v[r].first<x) l++;
  17. else if(v[l].first+v[r].first==x){
  18. cout<<v[l].second<<" "<<v[r].second;
  19. return 0;
  20. }
  21. }
  22.  
  23.  
  24. cout<<"-1";
  25. return 0;
  26. }
Success #stdin #stdout 0.01s 5304KB
stdin
Standard input is empty
stdout
-1