結果
問題 | No.1008 Bench Craftsman |
ユーザー | convexineq |
提出日時 | 2020-03-06 23:55:58 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 449 ms / 2,000 ms |
コード長 | 1,624 bytes |
コンパイル時間 | 187 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 133,616 KB |
最終ジャッジ日時 | 2024-04-22 10:57:32 |
合計ジャッジ時間 | 9,122 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
52,608 KB |
testcase_01 | AC | 41 ms
52,352 KB |
testcase_02 | AC | 41 ms
52,608 KB |
testcase_03 | AC | 41 ms
52,864 KB |
testcase_04 | AC | 44 ms
53,248 KB |
testcase_05 | AC | 449 ms
121,260 KB |
testcase_06 | AC | 215 ms
119,684 KB |
testcase_07 | AC | 42 ms
52,608 KB |
testcase_08 | AC | 65 ms
72,960 KB |
testcase_09 | AC | 236 ms
85,632 KB |
testcase_10 | AC | 386 ms
128,696 KB |
testcase_11 | AC | 389 ms
129,012 KB |
testcase_12 | AC | 391 ms
129,972 KB |
testcase_13 | AC | 381 ms
133,616 KB |
testcase_14 | AC | 386 ms
128,488 KB |
testcase_15 | AC | 299 ms
131,348 KB |
testcase_16 | AC | 348 ms
127,760 KB |
testcase_17 | AC | 297 ms
132,624 KB |
testcase_18 | AC | 342 ms
126,484 KB |
testcase_19 | AC | 341 ms
129,288 KB |
testcase_20 | AC | 247 ms
104,812 KB |
testcase_21 | AC | 241 ms
97,752 KB |
testcase_22 | AC | 285 ms
91,968 KB |
testcase_23 | AC | 358 ms
106,932 KB |
testcase_24 | AC | 345 ms
101,884 KB |
testcase_25 | AC | 224 ms
112,112 KB |
testcase_26 | AC | 196 ms
105,584 KB |
testcase_27 | AC | 241 ms
86,508 KB |
testcase_28 | AC | 296 ms
106,900 KB |
testcase_29 | AC | 391 ms
114,456 KB |
ソースコード
# coding: utf-8 # Your code here! import sys readline = sys.stdin.readline read = sys.stdin.read n,m = [int(i) for i in readline().split()] a = [int(i) for i in readline().split()] xw = [[int(i) for i in readline().split()] for _ in range(m)] V = 0 for i in range(m): xw[i][0] -= 1 V += xw[i][1] if V < min(a): print(0) exit() from itertools import accumulate def check(c): #耐久値 x で耐えられるか? imos = [0]*(n) res = [0]*(n) for x,w in xw: res[x] += w v = w//c l = max(0,x-v) r = x-1 #print(l,r) if l < r: X = w-(x-l)*c y = w-c imos[l] += X imos[l+1] += c-X if r+1 < n: imos[r+1] += -y-c if r+2 < n: imos[r+2] += y elif l==r: res[r] += w-c r = min(n-1,x+v) l = x+1 #print(l,r) if l < r: X = w-c y = w-c*(r-x) imos[l] += X imos[l+1] += -c-X if r+1 < n: imos[r+1] += -y+c if r+2 < n: imos[r+2] += y elif l==r: res[r] += w-c #print(x,w,c) #print(imos) #imos = [0]*n imos = accumulate(imos) imos = list(accumulate(imos)) #print(imos,res,a) return all(imos[i]+res[i] < a[i] for i in range(n)) #print(check(2)) ng = 0 ok = M = 10**6 while ok-ng > 1: mid = (ok+ng)//2 if check(mid): ok = mid else: ng = mid if ok < M: print(ok) else: print(-1)