結果

問題 No.1008 Bench Craftsman
ユーザー mkawa2mkawa2
提出日時 2020-03-07 14:16:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,361 bytes
コンパイル時間 697 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 17,696 KB
最終ジャッジ日時 2024-04-22 13:59:37
合計ジャッジ時間 4,441 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
17,696 KB
testcase_01 AC 32 ms
10,880 KB
testcase_02 AC 32 ms
10,752 KB
testcase_03 AC 34 ms
10,880 KB
testcase_04 AC 31 ms
10,752 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    def ok(c):
        if c==0:
            s=sum(w for i,w in xw)
            for a in aa:
                if a<=s:return False
            return True
        cs=[0]*n
        for i,w in xw:
            i-=1
            k=w//c
            if k==0:
                cs[i]+=w
                if i+1<n:cs[i+1]-=w*2
                if i+2<n:cs[i+2]+=w
            else:
                si=max(i-k,0)
                cs[si]+=w-c*(i-si)
                if si+1<n:cs[si+1]+=c-(w-c*(i-si))
                if i+1<n:cs[i+1]-=2*c
                if i+k+1<n:cs[i+k+1]+=c-(w-c*k)
                if i+k+2<n:cs[i+k+2]+=w-c*k
        for i in range(n-1):cs[i+1]+=cs[i]
        for i in range(n-1):cs[i+1]+=cs[i]
        for c,a in zip(cs,aa):
            if c>=a:return False
        return True

    n,m=MI()
    aa=LI()
    xw=LLI(m)
    l=-1
    r=inf=10**9+5
    while l+1<r:
        c=(l+r)//2
        if ok(c):r=c
        else:l=c
    if r==inf:print(-1)
    else:print(r)

main()
0