#include <bits/stdc++.h>
using namespace std;
const long long INF = 3e18;
int main() {
int n;
long long A, B;
cin >> n >> A >> B;
for(int t = 0; t < 100; t++) {
// cout << t << " " << (t + (t / B)) % A << " " << t % B << endl;
}
long long per;
if((INF / A) < B) {
per = INF;
} else {
per = A * B;
}
vector <pair <long long, long long>> v;
auto addRange = [&] (long long p, long long q) {
v.emplace_back(q, p);
// cout << p << " " << q << endl;
};
for(int i = 0; i < n; i++) {
long long p, q;
cin >> p >> q;
if((q - p + 1) >= per) {
cout << per << endl;
exit(0);
}
p %= per; q %= per;
if(p <= q) {
addRange(p, q);
} else {
addRange(p, per - 1);
addRange(0, q);
}
}
sort(v.begin(), v.end());
long long ans = 0;
long long last = -1;
for(auto i : v) {
long long l = i.second;
long long r = i.first;
ans += r - max(last + 1, l) + 1;
// cout << "from " << last << " to " << min << endl;
last = r;
}
cout << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Incorrect |
25 ms |
1152 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Incorrect |
7 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
2147 ms |
53628 KB |
Output is correct |
3 |
Incorrect |
2261 ms |
53608 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
2147 ms |
53628 KB |
Output is correct |
3 |
Incorrect |
2261 ms |
53608 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
2147 ms |
53628 KB |
Output is correct |
3 |
Incorrect |
2261 ms |
53608 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
227 ms |
5732 KB |
Output is correct |
3 |
Correct |
246 ms |
5732 KB |
Output is correct |
4 |
Correct |
2207 ms |
53600 KB |
Output is correct |
5 |
Correct |
217 ms |
5732 KB |
Output is correct |
6 |
Correct |
214 ms |
5732 KB |
Output is correct |
7 |
Correct |
245 ms |
5860 KB |
Output is correct |
8 |
Correct |
217 ms |
5736 KB |
Output is correct |
9 |
Correct |
214 ms |
5860 KB |
Output is correct |
10 |
Correct |
227 ms |
5732 KB |
Output is correct |
11 |
Correct |
225 ms |
5732 KB |
Output is correct |
12 |
Correct |
219 ms |
5732 KB |
Output is correct |
13 |
Correct |
224 ms |
5672 KB |
Output is correct |
14 |
Incorrect |
2163 ms |
53348 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Incorrect |
25 ms |
1152 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |