Submission #217048

#TimeUsernameProblemLanguageResultExecution timeMemory
217048sevlllStrange Device (APIO19_strange_device)Pypy 2
0 / 100
27 ms4960 KiB
from math import gcd from sys import exit n, a, b = map(int, input().split()) pr = [] for i in range(n): x, y = map(int, input().split()) pr.append((x, y)) g = gcd(a, b+1) num = a * b // g ev = [] for p in pr: l = p[0] r = p[1] if r - l + 1 >= num: print(num) exit(0) l %= num r %= num if r < l: ev += [(l, 1), (num, -1), (0, 1), (r+1, -1)] else: ev += [(l, 1), (r + 1, -1)] ev.sort() bal = 0 last = 0 ans = 0 for p in ev: x = p[0] tp = p[1] if bal: ans += x - last last = x bal += tp print ans
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...