Files
python/Algorithm/p4155.py
2026-01-31 14:37:51 +08:00

38 lines
799 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import collections
n = int(input())
m = int(input())
l = []
for i in range(n):
a = int(input())
b = int(input())
if b < a: b += m
l.append([a, b])
l.sort()
ans = []
# 第一个循环 选第几个人
for i in range(n):
a, b = l[i]
cnt = 0
# 第二个循环 开始往后迭代寻找最少需要几个人
# 流程: 比如 [2, 5] 指针从0到n往后找寻找最接近的5并小于的是4
# 把4的位置带入要解析的指针接着往后解析
p = i
while p < n:
tmp = p
for j in range(p, n):
if l[j][0] < l[p][1]:
tmp = j
if l[j][0] > l[p][1]:
break
if tmp != p:
cnt += 1
p = tmp
else:
break
ans.append(cnt)