#include <bits/stdc++.h>
#define int long long
#define endl "\n"
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, a, b;
cin >> n >> a >> b;
int k = a * b;
vector<pair<int, int>> segs;
for (int i = 0; i < n; i++) {
int l, r;
cin >> l >> r;
if (r - l + 1 >= k) {
segs.emplace_back(0, k - 1);
continue;
}
int l1 = l % k, r1 = r % k;
if (r1 < l1) {
segs.emplace_back(0, r1);
segs.emplace_back(l1, k - 1);
} else {
segs.emplace_back(l1, r1);
}
}
sort(segs.begin(), segs.end());
int mxr = -1;
int res = 0;
for (auto x : segs) {
res += max(x.second - max(mxr, x.first - 1), 0LL);
mxr = max(x.second, mxr);
}
cout << res << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
10 ms |
1152 KB |
Output is correct |
3 |
Correct |
10 ms |
1152 KB |
Output is correct |
4 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
380 ms |
31252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
530 ms |
34900 KB |
Output is correct |
3 |
Incorrect |
520 ms |
29652 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
530 ms |
34900 KB |
Output is correct |
3 |
Incorrect |
520 ms |
29652 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
530 ms |
34900 KB |
Output is correct |
3 |
Incorrect |
520 ms |
29652 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
61 ms |
5740 KB |
Output is correct |
3 |
Correct |
60 ms |
5740 KB |
Output is correct |
4 |
Correct |
629 ms |
29792 KB |
Output is correct |
5 |
Correct |
59 ms |
5740 KB |
Output is correct |
6 |
Correct |
58 ms |
5720 KB |
Output is correct |
7 |
Correct |
57 ms |
5740 KB |
Output is correct |
8 |
Correct |
72 ms |
5740 KB |
Output is correct |
9 |
Correct |
56 ms |
5740 KB |
Output is correct |
10 |
Correct |
57 ms |
5740 KB |
Output is correct |
11 |
Correct |
58 ms |
5740 KB |
Output is correct |
12 |
Correct |
56 ms |
5740 KB |
Output is correct |
13 |
Correct |
59 ms |
5868 KB |
Output is correct |
14 |
Correct |
547 ms |
29656 KB |
Output is correct |
15 |
Incorrect |
61 ms |
5740 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
10 ms |
1152 KB |
Output is correct |
3 |
Correct |
10 ms |
1152 KB |
Output is correct |
4 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |