import sys
input = lambda: sys.stdin.readline().strip()
from math import *
n,a,b = map(int, input().split())
ranges = []
for i in range(n):
ranges.append(list(map(int, input().split())))
k = (lcm(a,b+1)//(b+1)) * b
new = []
ans = 0
flag = False
for i in ranges:
if i[1]-i[0]+1 >= k:
flag = True
if i[0]%k > i[1]%k:
new.append([i[0]%k,k-1])
new.append([0,i[1]%k])
else:
new.append([i[0]%k, i[1]%k])
new.sort()
realnew = []
if flag:
print(k)
else:
cur = k
for i in range(len(new)):
if not realnew:
realnew.append(new[i])
continue
if realnew[-1][1] >= new[i][0]:
realnew[-1][1] = max(realnew[-1][1],new[i][1])
else:
realnew.append(new[i])
for i in realnew:
ans += i[1]-i[0]+1
print(ans)
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
70 ms |
20268 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
63 ms |
20148 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
61 ms |
20224 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
59 ms |
20200 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
59 ms |
20200 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
59 ms |
20200 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
56 ms |
20116 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
70 ms |
20268 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |