Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // bac_2020_var17_subIII_pb3
- #include <iostream>
- #include <fstream>
- using namespace std;
- ifstream fin("bac.txt");
- short v[10000];
- short n,a,b;
- short cauta(short a){
- short st = 0, dr = n-1;
- while(st<=dr){
- short mij=(st+dr)/2;
- if (v[mij]==a) return mij;
- if (v[mij]<a) st = mij+1;
- else dr = mij-1;
- }
- return dr;
- }
- int main()
- {
- fin >> n;
- for(short i=0; i<n; i++)
- fin >> v[i];
- while (fin >> a)
- {
- fin >> b;
- int poz1 = cauta (a);
- if (poz1>=0 && v[poz1]!=a && poz1+1<=n-1 && b<v[poz1+1]) cout << a << ' ' << b << endl;
- if (poz1<0 && b<v[0]) cout << a << ' ' << b << endl;
- if (poz1==n-1 && v[poz1]!=a) cout << a << ' ' << b << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement