제출 #1321807

#제출 시각아이디문제언어결과실행 시간메모리
1321807rycSnail (NOI18_snail)Pypy 3
100 / 100
148 ms51260 KiB
raw_input = input # python 2?
from builtins import input

INF = 1012345678012345678
BIG = 1000000000000
H, N = map(int, input().split())
assert(1<=H and H<=BIG)
assert(1<=N and N<=10000)
printed = False
P = []
simulate = []
# input data into P
P = list(map(int, input().split()))
# simulate for 2 days
simulate.append(0) # height at start of each phase
for i in range(2*N): # people may forget this
    simulate.append(max(simulate[i]+P[i%N], 0)) # people may leave out max
    if simulate[i+1] >= H: # >= is intended
        print("%d %d\n" % (i/N, i%N))
        printed = True
        break

increment = 0
if not printed:
    for i in range(N):
        increment += P[i]
    if increment <= 0:
        # not possible anymore
        print("-1 -1\n")
        printed = True

if not printed:
    bestDays = INF
    phase = 0
    for i in range(N):
        days = 1+(H-simulate[N+i+1]+increment-1)//increment;
        if bestDays > days:
            bestDays = days
            phase = i
    print("%d %d\n" % (bestDays, phase))
    printed = True

컴파일 시 표준 출력 (stdout) 메시지

Compiling 'snail.py'...

=======
  adding: __main__.pyc (deflated 28%)

=======
#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...