| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1349594 | akshar_7 | Safety (NOI18_safety) | Pypy 3 | 365 ms | 284840 KiB |
import heapq
from array import array
from sys import stdin
input = stdin.readline
def main():
input_data = stdin.read().split()
n = int(input_data[0])
h = int(input_data[1])
a = array('i', [int(x) for x in input_data[2:]])
del input_data
l = array('q', [-a[0]]); r = array('q', [a[0]])
ans = ls = rs = 0
for i in range(1,n):
x = a[i]
ls -= h
rs += h
if -l[0]+ls > x:
lx = -heapq.heappop(l)
ans += abs(x-(lx+ls))
heapq.heappush(l, -(x-ls))
heapq.heappush(l, -(x-ls))
heapq.heappush(r, lx+ls-rs)
elif r[0]+rs < x:
rx = heapq.heappop(r)
ans += abs(x-(rx+rs))
heapq.heappush(r, x-rs)
heapq.heappush(r, x-rs)
heapq.heappush(l, -(rx+rs-ls))
else:
heapq.heappush(l, -(x-ls))
heapq.heappush(r, x-rs)
return ans
print(main())컴파일 시 표준 출력 (stdout) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
