結果
| 問題 | 
                            No.2330 Eat Slime
                             | 
                    
| コンテスト | |
| ユーザー | 
                             gew1fw
                         | 
                    
| 提出日時 | 2025-06-12 13:05:07 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,296 bytes | 
| コンパイル時間 | 340 ms | 
| コンパイル使用メモリ | 82,816 KB | 
| 実行使用メモリ | 157,940 KB | 
| 最終ジャッジ日時 | 2025-06-12 13:10:23 | 
| 合計ジャッジ時間 | 7,000 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| 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)
    color_positions = {i: [] for i in range(1, 6)}
    for pos in range(1, N+1):
        color = C[pos-1]
        color_positions[color].append(pos)
    
    sum_Y = [0] * (N + 1)  # sum_Y[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
        
        positions = color_positions.get(B_j, [])
        if not positions:
            continue
        
        # Find the first position >= A_j using bisect
        idx_pos = bisect.bisect_left(positions, A_j)
        for pos in positions[idx_pos:]:
            K = pos - A_j
            if K <= N:  # Ensure K is within valid range
                sum_Y[K] += Y_j
    
    max_score = 0
    for K in range(N + 1):
        current = sum_Y[K] + K * X
        if current > max_score:
            max_score = current
    
    print(max_score)
if __name__ == "__main__":
    main()
            
            
            
        
            
gew1fw