juanjo12x

Live_Archive_6275

Oct 3rd, 2014
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6. int val = 10000000;
  7.  
  8.  
  9. int main(){
  10.     int x;
  11.     while(cin >> x){
  12.         //cout <<"f"<< x <<endl;
  13.         x *= val;
  14.  
  15.         vector<int> a;
  16.         int n; cin >> n;
  17.         for(int i = 0; i < n;i++){
  18.             int e; cin >> e;
  19.             a.push_back(e);
  20.         }
  21.         if(n==0 || n == 1){
  22.             cout << "danger"<<endl;
  23.             continue;
  24.         }
  25.         bool paso = false;
  26.         sort(a.begin(),a.end());
  27.         int i = 0;
  28.         int j = n-1;
  29.         while(i < j){
  30.             if(a[i]+a[j]==x){
  31.                 cout<<"yes"<<" "<<a[i]<<" "<<a[j]<<endl;
  32.                 paso = true;
  33.                 break;
  34.             }else if(a[i]+a[j]<x){
  35.                 i++;
  36.             }else if(a[i]+a[j]>x){
  37.                 j--;
  38.             }
  39.             //cout<<i<<" "<<j<<endl;
  40.  
  41.         }
  42.         if(!paso){
  43.             cout << "danger"<<endl;
  44.         }
  45.  
  46.     }
  47.  
  48.  
  49.     return 0;
  50. }
Add Comment
Please, Sign In to add comment