結果

問題 No.2423 Merge Stones
ユーザー miya145592
提出日時 2023-08-12 15:28:30
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 877 bytes
コンパイル時間 309 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 167,424 KB
最終ジャッジ日時 2024-11-20 02:36:20
合計ジャッジ時間 309,777 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 11 TLE * 61
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**7)

def dfs(a, c):
    n = len(a)
    if n==1:
        return max(a)
    ret = max(a)
    for i in range(n):
        if abs(c[i]-c[(i+1)%n])<=K:
            na = []
            nc = []
            idx = -1
            for j in range(n):
                if j==i:
                    idx = len(nc)
                    na.append(a[i]+a[(i+1)%n])
                    nc.append(c[i])
                elif j==(i+1)%n:
                    pass
                else:
                    na.append(a[j])
                    nc.append(c[j])
            ret1 = dfs(na, nc)
            ret = max(ret, ret1)
            nc[idx] = c[(i+1)%n]
            ret2 = dfs(na, nc)
            ret = max(ret, ret2)
    return ret

N, K = map(int, input().split())
A = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = dfs(A, C)
print(ans)
0