新手蒟蒻超时了,该怎么节约时间呢
import math
N,D,K=map(int,input().split())
list1=[]
hot=[]
for i in range(N):
list1.append(list(map(int,input().split())))
# print(list1)
for i in range(len(list1)):
count=0
for j in range(i,len(list1)):
if list1[i][1]==list1[j][1] and abs(list1[j][0]-list1[i][0] )<D:
count+=1
if count>=K and list1[i][1] not in hot:
hot.append(list1[i][1])
break
hot.sort()
flag=[]
for i in hot:
# if i not in flag:
#
# print(i)
# flag.append(i)
print(i)
import math
N, D, K = map(int, input().split())
list1 = []
hot = []
dic = {}
for i in range(N):
list1.append(list(map(int, input().split())))
# print(list1)
for i in range(len(list1)):
count = 0
ts,id = list1[i][0],list1[i][1]
if id not in dic:
dic[id] = {}
s = (ts // 10) * 10
m = (s, s + D)
if m not in dic[id]:
dic[id][m] = 1
else:
dic[id][m] += 1
res = []
for i, j in dic.items():
for s in j.values():
if s >= K:
res.append(i)
break
for i in res:
print(i)
hhh,你要看看我的吗
N,D,K = map(int,input().split())
dic = {}
output = [] # 输出的id不是有序的,将其放入到output排序后再输出,内存大,任性
for _ in range(N):
t,i = map(int,input().split())
if i not in dic:
dic[i] = [t]
else:
dic[i].append(t)
for i in dic:
l = dic[i]
length = len(l)
if length < K:
continue
l.sort()
for j in range(length):
if j+K-1 < length:
if l[j+K-1] - l[j] < D:
output.append(i)
break
output.sort()
for i in output:
print(i)