結果

問題 No.1290 Addition and Subtraction Operation
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-02-18 12:42:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 343 ms / 2,000 ms
コード長 742 bytes
コンパイル時間 397 ms
コンパイル使用メモリ 87,048 KB
実行使用メモリ 116,716 KB
最終ジャッジ日時 2023-10-12 21:26:28
合計ジャッジ時間 14,348 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,136 KB
testcase_01 AC 71 ms
71,180 KB
testcase_02 AC 72 ms
71,204 KB
testcase_03 AC 71 ms
71,388 KB
testcase_04 AC 73 ms
71,328 KB
testcase_05 AC 72 ms
71,144 KB
testcase_06 AC 71 ms
71,276 KB
testcase_07 AC 72 ms
71,236 KB
testcase_08 AC 72 ms
71,376 KB
testcase_09 AC 73 ms
71,480 KB
testcase_10 AC 72 ms
71,260 KB
testcase_11 AC 71 ms
71,144 KB
testcase_12 AC 70 ms
70,928 KB
testcase_13 AC 70 ms
71,000 KB
testcase_14 AC 69 ms
71,308 KB
testcase_15 AC 72 ms
71,388 KB
testcase_16 AC 72 ms
71,144 KB
testcase_17 AC 71 ms
70,976 KB
testcase_18 AC 72 ms
71,448 KB
testcase_19 AC 73 ms
71,136 KB
testcase_20 AC 71 ms
71,000 KB
testcase_21 AC 70 ms
71,140 KB
testcase_22 AC 72 ms
71,204 KB
testcase_23 AC 73 ms
71,528 KB
testcase_24 AC 72 ms
71,384 KB
testcase_25 AC 72 ms
71,168 KB
testcase_26 AC 72 ms
71,320 KB
testcase_27 AC 72 ms
70,992 KB
testcase_28 AC 71 ms
71,348 KB
testcase_29 AC 71 ms
71,320 KB
testcase_30 AC 71 ms
71,176 KB
testcase_31 AC 71 ms
71,088 KB
testcase_32 AC 71 ms
71,324 KB
testcase_33 AC 71 ms
71,268 KB
testcase_34 AC 71 ms
71,328 KB
testcase_35 AC 71 ms
71,152 KB
testcase_36 AC 71 ms
71,268 KB
testcase_37 AC 70 ms
71,144 KB
testcase_38 AC 72 ms
71,308 KB
testcase_39 AC 71 ms
71,228 KB
testcase_40 AC 73 ms
71,176 KB
testcase_41 AC 71 ms
71,112 KB
testcase_42 AC 153 ms
89,500 KB
testcase_43 AC 154 ms
89,236 KB
testcase_44 AC 156 ms
89,264 KB
testcase_45 AC 158 ms
89,296 KB
testcase_46 AC 159 ms
89,380 KB
testcase_47 AC 156 ms
89,500 KB
testcase_48 AC 150 ms
89,424 KB
testcase_49 AC 164 ms
89,568 KB
testcase_50 AC 157 ms
89,316 KB
testcase_51 AC 156 ms
89,576 KB
testcase_52 AC 158 ms
89,444 KB
testcase_53 AC 159 ms
89,360 KB
testcase_54 AC 155 ms
89,260 KB
testcase_55 AC 157 ms
89,288 KB
testcase_56 AC 158 ms
89,492 KB
testcase_57 AC 133 ms
89,484 KB
testcase_58 AC 155 ms
95,552 KB
testcase_59 AC 134 ms
90,964 KB
testcase_60 AC 178 ms
95,324 KB
testcase_61 AC 167 ms
95,296 KB
testcase_62 AC 162 ms
93,232 KB
testcase_63 AC 151 ms
96,860 KB
testcase_64 AC 119 ms
97,468 KB
testcase_65 AC 120 ms
89,468 KB
testcase_66 AC 147 ms
90,992 KB
testcase_67 AC 171 ms
95,644 KB
testcase_68 AC 161 ms
92,532 KB
testcase_69 AC 154 ms
96,580 KB
testcase_70 AC 134 ms
89,684 KB
testcase_71 AC 144 ms
90,820 KB
testcase_72 AC 122 ms
89,824 KB
testcase_73 AC 170 ms
101,060 KB
testcase_74 AC 110 ms
96,328 KB
testcase_75 AC 122 ms
89,588 KB
testcase_76 AC 137 ms
89,840 KB
testcase_77 AC 280 ms
109,084 KB
testcase_78 AC 256 ms
105,820 KB
testcase_79 AC 202 ms
99,212 KB
testcase_80 AC 337 ms
116,716 KB
testcase_81 AC 343 ms
116,356 KB
testcase_82 AC 156 ms
90,832 KB
testcase_83 AC 184 ms
97,572 KB
testcase_84 AC 211 ms
104,360 KB
testcase_85 AC 143 ms
91,960 KB
testcase_86 AC 118 ms
90,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main1(n,m,b,lr):
  b=[x*(-1)**i for i,x in enumerate(b)]
  rary=[set() for _ in range(n)]
  for l,r in lr:rary[l-1].add(r)
  ary=[0]*(n+1)
  now=0
  for i in range(n):
    now-=ary[i]
    stc=set()
    d=0
    while rary[i]:
      r=rary[i].pop()
      stc.add(r)
      d=b[i]-now
    if stc:
      stc=list(stc)
      stc.sort()
      for x,y in zip(stc[0:],stc[1:]):
        rary[x].add(y)
      ary[stc[0]]+=d
      now+=d
    if b[i]==now:
      pass
    else:
      return False
  return True
import sys
input=sys.stdin.readline
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)]
  ret1=main1(n,m,b,lr)
  print('YES' if ret1 else 'NO')
0