AcWing 3248. 公共钥匙盒 ( 用python巨简单)
原题链接
简单
作者:
凪you
,
2024-12-08 20:06:24
,
所有人可见
,
阅读 5
用python巨简单
总体的思路就是差分过程,把借和还这两个过程拆分出来,进行排序就OK了。
n,k = map(int,input().split())
h = [i for i in range(n + 1)]
v = []
for i in range(k):
w,s,c = map(int,input().split())
v.append([s,w,1]) # 1代表借
v.append([s + c,w,0]) # 0代表还
v.sort(key = lambda x : (x[0],x[2],x[1]))
for i in range(len(v)):
if v[i][2] == 1:
for j in range(1 , n + 1):
if(h[j] == v[i][1]):
h[j] = -1
if v[i][2] == 0:
for j in range(1 , n + 1):
if h[j] == -1:
h[j] = v[i][1]
break
for i in range(1 , n + 1): print(h[i] , end = ' ')