#include <iostream> using namespace std; long long n,m,s; long long a,b; long long a2,b2; int main() { cin>>n>>m>>s; for(long long i=0; i<m; i++){ cin>>a2>>b2; if((s>=a2)&&(s<=b2)){ a=a2; b=b2; } } if(s-a<=b-s){ if(a>1){ cout<<a-1; return 0; } else{ cout<<b+1; return 0; } }else{ if(b<n){ cout<<b+1; return 0; } else{ cout<<a-1; return 0; } } 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 | #include <iostream> using namespace std; long long n,m,s; long long a,b; long long a2,b2; int main() { cin>>n>>m>>s; for(long long i=0; i<m; i++){ cin>>a2>>b2; if((s>=a2)&&(s<=b2)){ a=a2; b=b2; } } if(s-a<=b-s){ if(a>1){ cout<<a-1; return 0; } else{ cout<<b+1; return 0; } }else{ if(b<n){ cout<<b+1; return 0; } else{ cout<<a-1; return 0; } } return 0; } |