Joao_Joao

Soma de Casas - C++

Aug 16th, 2020 (edited)
127
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;typedef long double lf;typedef double fl;typedef string str;
  5. typedef vector<int> vi;typedef vector<vector<int>> vvi;typedef vector<fl> vf;typedef vector<ll> vl;
  6. typedef vector<lf> vlf;typedef vector<char> vc;typedef vector<str> vs;typedef pair<int,int> ii;
  7.  
  8. # define f(i,a,b,c) for(ll i=a;i<b;i+=c)
  9. # define fd(i,a,b,c) for(ll i=a;i>=b;i-=c)
  10. # define ctoi(a) (a-'0')
  11.  
  12. int ns[100000], n, x, i=0, j;
  13. void au(){
  14.     j = n-1;
  15.    
  16.     while(i<j){
  17.         if(ns[i]+ns[j] == x){
  18.             cout<<ns[i]<<' '<<ns[j]<<'\n';
  19.             return;
  20.         }
  21.         else if(ns[i]+ns[j]<x)++i;
  22.         else --j;
  23.     }
  24. }
  25. int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.precision(2);cout.setf(ios::fixed);
  26.     cin>>n;
  27.     f(i,0,n,1)cin>>ns[i];
  28.     cin>>x, au();
  29. }
  30.  
RAW Paste Data Copied