結果

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

ソースコード

diff #

from bisect import bisect_left
from collections import defaultdict

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 color positions (1-based)
    color_pos = [[] for _ in range(6)]  # colors 1-5
    for i in range(N):
        c = C[i]
        color_pos[c].append(i + 1)  # positions are 1-based
    
    sum_Y = defaultdict(int)
    for _ in range(M):
        a = int(data[idx])
        idx += 1
        b = int(data[idx])
        idx += 1
        y = int(data[idx])
        idx += 1
        sum_Y[(a, b)] += y
    
    score = [0] * (N + 1)  # score[k] for 0 <= k <= N
    
    for (a, b), y_total in sum_Y.items():
        if not color_pos[b]:
            continue
        lst = color_pos[b]
        idx_a = bisect_left(lst, a)
        for i in lst[idx_a:]:
            k = i - a
            if k <= N:
                score[k] += y_total
    
    max_total = 0
    for k in range(N + 1):
        current = X * k + score[k]
        if current > max_total:
            max_total = current
    
    print(max_total)

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