結果

問題 No.2330 Eat Slime
ユーザー lam6er
提出日時 2025-04-16 15:34:53
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,279 bytes
コンパイル時間 426 ms
コンパイル使用メモリ 81,800 KB
実行使用メモリ 157,812 KB
最終ジャッジ日時 2025-04-16 15:39:24
合計ジャッジ時間 6,936 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 5 TLE * 1 -- * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect

def main():
    import sys
    input = sys.stdin.read
    data = input().split()
    idx = 0
    N = int(data[idx])
    idx += 1
    M = int(data[idx])
    idx += 1
    X = int(data[idx])
    idx += 1
    
    C = list(map(int, data[idx:idx+N]))
    idx += N
    
    # Preprocess positions for each color (1-based)
    pos = [[] for _ in range(6)]  # colors 1-5
    for i in range(N):
        c = C[i]
        pos[c].append(i + 1)  # positions are 1-based
    
    ans = [0] * (N + 1)  # ans[k] for 0 <= k <= N
    
    for _ in range(M):
        A_j = int(data[idx])
        idx += 1
        B_j = int(data[idx])
        idx += 1
        Y_j = int(data[idx])
        idx += 1
        
        # Get positions for B_j
        lst = pos[B_j]
        # Find the first index where position >= A_j
        idx_p = bisect.bisect_left(lst, A_j)
        # Iterate from idx_p to end of lst, but ensure p <= N
        for p in lst[idx_p:]:
            if p > N:
                break
            k = p - A_j
            if k <= N:
                ans[k] += Y_j
    
    max_score = 0
    for k in range(N + 1):
        current = X * k + ans[k]
        if current > max_score:
            max_score = current
    
    print(max_score)

if __name__ == "__main__":
    main()
0