i don't think it spend much time, but it takes more than i expected.
i think for - if is the problem.
what makes it takes a lot of times?
is there a better way to reduce time?
the problem is that
n = number of flowers
a, b = blooming date of flowers (month, date) c, d = fall date of flowers (month, date)
(when fall date of flowers you can't see that flower) (if 0530 is fall date, then you can't see that flower on 0530)
i want to see flowers every day from 0301 ~ 1130
print minimum of needed flowers
i was told that it is greedy algorithm problem.
sorry for my english
i don't know how to reduce time anymore
i think it's a proper way to solve this problem
here's my code below
flo_list = []
n = int(input())
for i in range(n) :
a, b, c, d = map(int, input().split())
flo_list.append((a*100 + b, c*100 + d))
flo_list.sort(reverse = True)
cnt = 0
srt_flo = sorted(flo_list, key = lambda i : i[1], reverse = True)
if flo_list[-1][0] > 301 :
print(0)
exit()
if srt_flo[0][1] < 1201 :
print(0)
exit()
for (i, j) in srt_flo :
if i <= 301 :
(f, e) = (i, j)
cnt = cnt + 1
break
while e < 1201 :
for (i, j) in srt_flo :
if f < i <= e :
(f, e) = (i, j)
cnt = cnt + 1
break
else :
cnt = 0
break
print(cnt)
Aucun commentaire:
Enregistrer un commentaire