結果
| 問題 | 
                            No.2330 Eat Slime
                             | 
                    
| コンテスト | |
| ユーザー | 
                             lam6er
                         | 
                    
| 提出日時 | 2025-04-15 21:30:35 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,279 bytes | 
| コンパイル時間 | 295 ms | 
| コンパイル使用メモリ | 82,148 KB | 
| 実行使用メモリ | 53,408 KB | 
| 最終ジャッジ日時 | 2025-04-15 21:33:24 | 
| 合計ジャッジ時間 | 6,696 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 5 TLE * 1 -- * 24 | 
ソースコード
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()
            
            
            
        
            
lam6er