結果

問題 No.2662 Installing Cell Towers
ユーザー hato336hato336
提出日時 2024-03-06 15:51:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 423 ms / 2,000 ms
コード長 997 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 109,280 KB
最終ジャッジ日時 2024-03-06 15:51:14
合計ジャッジ時間 6,708 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
84,920 KB
testcase_01 AC 123 ms
84,920 KB
testcase_02 AC 121 ms
84,920 KB
testcase_03 AC 122 ms
84,920 KB
testcase_04 AC 287 ms
91,400 KB
testcase_05 AC 408 ms
105,672 KB
testcase_06 AC 233 ms
96,312 KB
testcase_07 AC 122 ms
84,920 KB
testcase_08 AC 260 ms
96,088 KB
testcase_09 AC 273 ms
91,824 KB
testcase_10 AC 303 ms
104,652 KB
testcase_11 AC 315 ms
103,652 KB
testcase_12 AC 119 ms
84,920 KB
testcase_13 AC 205 ms
96,752 KB
testcase_14 AC 310 ms
105,096 KB
testcase_15 AC 423 ms
101,264 KB
testcase_16 AC 120 ms
84,920 KB
testcase_17 AC 243 ms
109,276 KB
testcase_18 AC 219 ms
109,280 KB
testcase_19 AC 121 ms
84,920 KB
testcase_20 AC 119 ms
84,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random
#sys.setrecursionlimit(10**9)
#sys.set_int_max_str_digits(0)
input = sys.stdin.readline
n,m = map(int,input().split())
check = [[] for i in range(n)]
c = [0 for i in range(n)]
for i in range(m):
    p,q = map(int,input().split())
    p -= 1
    check[p].append(q)
r = [0 for i in range(n)]
temp = 0
cnt = 0
h = []
for i in range(n):
    for j in check[i]:
        temp += j
        cnt += 1
        heapq.heappush(h,i+j)
    r[i] = temp
    while h and h[0] == i:
        cnt -= 1
        heapq.heappop(h)
    temp = max(temp-cnt,0)

l = [0 for i in range(n)]
temp = 0
cnt = 0
h = []
for i in reversed(range(n)):
    for j in check[i]:
        temp += j
        cnt += 1
        heapq.heappush(h,-(i-j))
    l[i] = temp
    while h and h[0] == -i:
        cnt -= 1
        heapq.heappop(h)
    temp = max(temp-cnt,0)
for i in range(n):
    print(l[i]+r[i]-sum(check[i]),end=' ')

#0 1 3 4 5 5 3 2 1 0
0