結果

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

ソースコード

diff #

import bisect
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
    
    color_positions = defaultdict(list)
    for pos in range(N):
        color = C[pos]
        color_positions[color].append(pos + 1)  # positions are 1-based
    
    sum_Yj = [0] * (N + 1)  # sum_Yj[K] for K from 0 to 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
        
        pos_list = color_positions.get(B_j, [])
        if not pos_list:
            continue
        
        # Find the first position >= A_j
        idx_pos = bisect.bisect_left(pos_list, A_j)
        for pos in pos_list[idx_pos:]:
            K = pos - A_j
            if K <= N:
                sum_Yj[K] += Y_j
    
    max_score = 0
    for K in range(N + 1):
        current = K * X + sum_Yj[K]
        if current > max_score:
            max_score = current
    print(max_score)

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