結果

問題 No.2423 Merge Stones
ユーザー pあり
提出日時 2023-08-12 15:43:53
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 525 bytes
コンパイル時間 311 ms
コンパイル使用メモリ 82,404 KB
実行使用メモリ 76,204 KB
最終ジャッジ日時 2024-11-20 04:06:17
合計ジャッジ時間 7,283 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 52 WA * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

n,k = map(int, input().split())

a = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0
for i in range(n):
  aa = a[i:] + a[:i]
  cc = c[i:] + c[:i]
  
  ok = [cc[0]]
  now = aa[0]
  for j in range(1, n):
    ok2 = []
    for v in ok:
      if(cc[j]-k <= v and v <= cc[j]+k):
        ok2.append(v)
        
    
    
    if(len(ok2)==0):
      break
    ok.append(cc[j])
    now+=aa[j]
    #print(i,j,ok2, now)
    #ok = ok2
    
  ans = max(ans, now)
  #print(i, ans)
  
print(ans)
    
    
  
  
0