/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <iostream>
#include <vector>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long n,m,s;
cin >> n >> m >> s;
vector <bool> t(n , true);
for(int i=0; i<m; i++){
int p,l;
cin >> l >> p;
for(int j=l; j<=p; j++){
t[j]=false;
}
}
for(int i=1; i<=n/2; i++){
if(t[s-i]==true || t[s+i]==true){
if(t[s-i]==true){
cout << s-i;
return 0;
}
cout << s+i;
return 0;
}
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | /****************************************************************************** Welcome to GDB Online. GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl, C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog. Code, Compile, Run and Debug online from anywhere in world. *******************************************************************************/ #include <iostream> #include <vector> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long n,m,s; cin >> n >> m >> s; vector <bool> t(n , true); for(int i=0; i<m; i++){ int p,l; cin >> l >> p; for(int j=l; j<=p; j++){ t[j]=false; } } for(int i=1; i<=n/2; i++){ if(t[s-i]==true || t[s+i]==true){ if(t[s-i]==true){ cout << s-i; return 0; } cout << s+i; return 0; } } } |
English