#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pp pop_back
#define mp make_pair
#define bb back
#define ff first
#define ss second
#define int long long
using namespace std;
/*
____ __ _______ _______ __________
| \ | | | _____| / _____) |____ ____|
| |\ \ | | | |__ ( (_____ | |
| | \ \| | | __| \_____ \ | |
| | \ | | |_____ _____) ) | |
|__| \____| |_______| (_______/ |__|
*/
int INF = LLONG_MAX;
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, A, B, I, gcd, k, l, r;
cin >> n >> A >> B;
gcd = __gcd(A, B+1);
if (gcd == 1) k = A;
else k = A / gcd;
if (INF / k <= B)
I = INF;
else
I = k*B;
vector<pair<int, int> > rem;
for (int i = 0; i < n; i++) {
cin >> l >> r;
if (r-l+1 >= I) {
rem.pb({0, I});
} else if (l%I > r%I) {
rem.pb({l%I, I-1});
rem.pb({0, r%I});
} else {
rem.pb({l%I, r%I});
}
}
int L = 0, ans = 0;
sort(rem.begin(), rem.end());
for (auto el : rem) {
el.ff = max(el.ff, L);
if (el.ff > el.ss)
continue;
ans += el.ss-el.ff+1;
L = max(L, el.ss+1);
}
cout << ans << '\n';
return 0;
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |