結果
| 問題 | 
                            No.865 24時間降水量
                             | 
                    
| コンテスト | |
| ユーザー | 
                             htensai
                         | 
                    
| 提出日時 | 2020-05-15 17:49:44 | 
| 言語 | Java  (openjdk 23)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 1,246 ms / 2,000 ms | 
| コード長 | 1,138 bytes | 
| コンパイル時間 | 2,129 ms | 
| コンパイル使用メモリ | 77,968 KB | 
| 実行使用メモリ | 74,588 KB | 
| 最終ジャッジ日時 | 2024-09-19 05:02:21 | 
| 合計ジャッジ時間 | 10,061 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 18 | 
ソースコード
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n + 1];
        int[] sums = new int[n + 1];
        int[] total24 = new int[n + 1 - 23];
        for (int i = 1; i <= n; i++) {
            arr[i] = sc.nextInt();
            sums[i] = sums[i - 1] + arr[i];
        }
        int max = 0;
        for (int i = 24; i <= n; i++) {
            total24[i - 23] = sums[i] - sums[i - 24];
            max = Math.max(total24[i - 23], max);
        }
        int q = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < q; i++) {
            int time = sc.nextInt();
            int value = sc.nextInt();
            int add = value - arr[time];
            arr[time] = value;
            for (int j = Math.max(time - 23, 1); j <= time && j < total24.length; j++) {
                total24[j] += add;
                max = Math.max(max, total24[j]);
            }
            sb.append(max).append("\n");
        }
        System.out.print(sb);
    }
}
            
            
            
        
            
htensai