#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define ll long long
ll n, m, s, wynik = 0, lewo, prawo;
int main(){
cin >> n >> m >> s;
vector<ll> Bajtocja (n+1, 0);
lewo = s;
prawo = s;
ll x, y;
Bajtocja[s] = 1;
for (int i = 1; i <= m; i ++){
cin >> x >> y;
for (int j = x; j <= y; j ++){
Bajtocja[j] = 1;
}
}
while (prawo <= n and lewo >= 0){
lewo --;
prawo ++;
if (Bajtocja[lewo] == 0){
cout << lewo;
return 0;
}
if (Bajtocja[prawo] == 0){
cout << prawo;
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 | #include <iostream> #include <algorithm> #include <vector> using namespace std; #define ll long long ll n, m, s, wynik = 0, lewo, prawo; int main(){ cin >> n >> m >> s; vector<ll> Bajtocja (n+1, 0); lewo = s; prawo = s; ll x, y; Bajtocja[s] = 1; for (int i = 1; i <= m; i ++){ cin >> x >> y; for (int j = x; j <= y; j ++){ Bajtocja[j] = 1; } } while (prawo <= n and lewo >= 0){ lewo --; prawo ++; if (Bajtocja[lewo] == 0){ cout << lewo; return 0; } if (Bajtocja[prawo] == 0){ cout << prawo; return 0; } } } |
English