結果

問題 No.1290 Addition and Subtraction Operation
ユーザー persimmon-persimmon
提出日時 2021-02-18 11:27:46
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 742 bytes
コンパイル時間 390 ms
コンパイル使用メモリ 82,156 KB
実行使用メモリ 169,868 KB
最終ジャッジ日時 2024-09-14 18:28:06
合計ジャッジ時間 8,068 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 40 TLE * 1 -- * 44
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=sys.stdin.readline
def main2(n,m,b_,lr):
  from heapq import heappop,heappush
  b=[x*(-1)**i for i,x in enumerate(b_)]
  lr.sort(key=lambda x:x[0])
  ary=[0]*(n+1)
  now=0
  for i in range(n):
    now-=ary[i]
    stc=[]
    mir=n
    d=0
    while lr and lr[0][0]-1==i:
      l,r=heappop(lr)
      stc.append(r)
      mir=min(mir,r)
      d=b[i]-now
    ary[mir]+=d
    for r in stc:
      if r==mir:continue
      heappush(lr,[mir+1,r])
    now+=d
    if b[i]==now:
      pass
    else:
      return False
  return True
if __name__=='__main__':
  n,m=map(int,input().split())
  b=list(map(int,input().split()))
  lr=[list(map(int,input().split())) for _ in range(m)]
  ret2=main2(n,m,b,lr)
  print('YES' if ret2 else 'NO')
0