#include <bits/stdc++.h>
using namespace std;
inline namespace
{
} // namespace
void solve()
{
int n;
long a, b;
cin >> n >> a >> b;
vector<array<long, 2>> v(n);
for (auto &[x, y] : v)
cin >> x >> y, ++y;
long c = a * b / gcd(a, b + 1);
vector<array<long, 2>> u;
for (auto [x, y] : v)
{
if (y - x >= c)
u.push_back({0, c});
else
{
x %= c, y %= c;
if (x < y)
u.push_back({x, y});
else
u.push_back({x, c}), u.push_back({0, y});
}
}
sort(u.begin(), u.end());
long cnt = 0;
long d = 0;
for (auto [x, y] : u)
{
if (y > d)
{
cnt += y - max(x, d);
d = y;
}
}
cout << cnt << '\n';
}
int main()
{
ios_base::sync_with_stdio(false), cin.tie(NULL);
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
1244 KB |
Output is correct |
3 |
Correct |
6 ms |
1248 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
320 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
1244 KB |
Output is correct |
17 |
Correct |
50 ms |
7760 KB |
Output is correct |
18 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
0 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
328 ms |
33204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
474 ms |
44872 KB |
Output is correct |
3 |
Correct |
442 ms |
33768 KB |
Output is correct |
4 |
Correct |
468 ms |
56228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
474 ms |
44872 KB |
Output is correct |
3 |
Correct |
442 ms |
33768 KB |
Output is correct |
4 |
Correct |
468 ms |
56228 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
459 ms |
57580 KB |
Output is correct |
7 |
Correct |
460 ms |
57124 KB |
Output is correct |
8 |
Correct |
453 ms |
57988 KB |
Output is correct |
9 |
Correct |
482 ms |
56824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
474 ms |
44872 KB |
Output is correct |
3 |
Correct |
442 ms |
33768 KB |
Output is correct |
4 |
Correct |
468 ms |
56228 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
44 ms |
7748 KB |
Output is correct |
7 |
Correct |
47 ms |
7768 KB |
Output is correct |
8 |
Correct |
47 ms |
7772 KB |
Output is correct |
9 |
Correct |
43 ms |
7752 KB |
Output is correct |
10 |
Correct |
44 ms |
7760 KB |
Output is correct |
11 |
Correct |
47 ms |
7744 KB |
Output is correct |
12 |
Correct |
43 ms |
7744 KB |
Output is correct |
13 |
Correct |
47 ms |
7740 KB |
Output is correct |
14 |
Correct |
42 ms |
7764 KB |
Output is correct |
15 |
Correct |
47 ms |
7764 KB |
Output is correct |
16 |
Correct |
48 ms |
7760 KB |
Output is correct |
17 |
Correct |
45 ms |
7748 KB |
Output is correct |
18 |
Correct |
462 ms |
58020 KB |
Output is correct |
19 |
Correct |
445 ms |
56472 KB |
Output is correct |
20 |
Correct |
504 ms |
57288 KB |
Output is correct |
21 |
Correct |
48 ms |
7760 KB |
Output is correct |
22 |
Correct |
44 ms |
7764 KB |
Output is correct |
23 |
Correct |
139 ms |
26488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
47 ms |
7748 KB |
Output is correct |
3 |
Correct |
45 ms |
7760 KB |
Output is correct |
4 |
Correct |
488 ms |
33992 KB |
Output is correct |
5 |
Correct |
49 ms |
7748 KB |
Output is correct |
6 |
Correct |
47 ms |
7748 KB |
Output is correct |
7 |
Correct |
47 ms |
7748 KB |
Output is correct |
8 |
Correct |
49 ms |
7748 KB |
Output is correct |
9 |
Correct |
49 ms |
7748 KB |
Output is correct |
10 |
Correct |
47 ms |
7756 KB |
Output is correct |
11 |
Correct |
46 ms |
7740 KB |
Output is correct |
12 |
Correct |
40 ms |
7752 KB |
Output is correct |
13 |
Correct |
47 ms |
7748 KB |
Output is correct |
14 |
Correct |
479 ms |
34016 KB |
Output is correct |
15 |
Correct |
47 ms |
7748 KB |
Output is correct |
16 |
Correct |
432 ms |
38588 KB |
Output is correct |
17 |
Correct |
441 ms |
45496 KB |
Output is correct |
18 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
1244 KB |
Output is correct |
3 |
Correct |
6 ms |
1248 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
320 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
1244 KB |
Output is correct |
17 |
Correct |
50 ms |
7760 KB |
Output is correct |
18 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |