#include<bits/stdc++.h>
using namespace std;
#define ioss ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
int n, a, b;
bool comp(pii a, pii b) {
return (a.fi < b.fi || (a.fi == b.fi && a.se < b.se));
}
signed main() {
ioss;
cin >> n >> a >> b;
int tmp = a*b;
if((b+1)%a == 0) tmp = b;
vector<pii> idx;
for(int i = 0; i < n; i++) {
int l, r; cin >> l >> r;
l %= tmp, r %= tmp;
if(r < l) r += tmp;
idx.pb({l, r});
}
sort(idx.begin(), idx.end(), comp);
int ans = 0;
for(int i = 0; i < n; i++) {
auto [l, r] = idx[i];
if((r-l)+1 >= tmp) {
ans = tmp;
break;
}
if(i == 0) ans += (r-l)+1;
else {
auto [x, y] = idx[i-1];
if(x <= l && y >= l) l = y+1;
else if(x <= r && y >= r) r = x-1;
else if(x <= l && y >= r) continue;
ans += (r-l)+1;
}
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
4 ms |
792 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
409 ms |
16988 KB |
Output is correct |
3 |
Incorrect |
390 ms |
16984 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
409 ms |
16988 KB |
Output is correct |
3 |
Incorrect |
390 ms |
16984 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
409 ms |
16988 KB |
Output is correct |
3 |
Incorrect |
390 ms |
16984 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
46 ms |
2748 KB |
Output is correct |
3 |
Correct |
42 ms |
2820 KB |
Output is correct |
4 |
Correct |
472 ms |
17040 KB |
Output is correct |
5 |
Correct |
54 ms |
3216 KB |
Output is correct |
6 |
Correct |
44 ms |
3108 KB |
Output is correct |
7 |
Correct |
44 ms |
3232 KB |
Output is correct |
8 |
Correct |
47 ms |
3192 KB |
Output is correct |
9 |
Correct |
42 ms |
3204 KB |
Output is correct |
10 |
Correct |
45 ms |
3188 KB |
Output is correct |
11 |
Correct |
44 ms |
3220 KB |
Output is correct |
12 |
Correct |
35 ms |
3220 KB |
Output is correct |
13 |
Correct |
50 ms |
3212 KB |
Output is correct |
14 |
Incorrect |
433 ms |
17136 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
4 ms |
792 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |