Submission #636862

# Submission time Handle Problem Language Result Execution time Memory
636862 2022-08-30T10:32:46 Z beaconmc Strange Device (APIO19_strange_device) PyPy 3
0 / 100
66 ms 20264 KB
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 63 ms 20164 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 20144 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 20228 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 58 ms 20264 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 58 ms 20264 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 58 ms 20264 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 66 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 63 ms 20164 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -