結果

問題 No.865 24時間降水量
ユーザー takeya_okino
提出日時 2019-08-18 09:34:21
言語 Java
(openjdk 23)
結果
AC  
実行時間 1,958 ms / 2,000 ms
コード長 1,060 bytes
コンパイル時間 2,055 ms
コンパイル使用メモリ 77,612 KB
実行使用メモリ 63,980 KB
最終ジャッジ日時 2024-10-01 13:38:33
合計ジャッジ時間 13,385 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] rui = new long[n];
    long[] a = new long[n];
    for(int i = 0; i < n; i++) {
      a[i] = sc.nextLong();
      if(i == 0) {
        rui[i] = a[i];
      } else {
        rui[i] = rui[i - 1] + a[i];
      }
    }
    long[] kukan = new long[n - 23];
    for(int i = 0; i < n - 23; i++) {
      if(i == 0) {
        kukan[i] = rui[i + 23]; 
      } else {
        kukan[i] = rui[i + 23] - rui[i - 1];
      }  
    }
    long ans = 0;
    for(int i = 0; i < n - 23; i++) {
      ans = Math.max(ans, kukan[i]);
    }
    int q = sc.nextInt();
    for(int i = 0; i < q; i++) {
      int t = sc.nextInt() - 1;
      long v = sc.nextLong();
      long sa = v - a[t];
      a[t] = v;
      for(int j = t - 23; j <= t; j++) {
        if((j >= 0) && (j < n - 23)) {
          kukan[j] = kukan[j] + sa;
          ans = Math.max(ans, kukan[j]);
        } 
      }
      System.out.println(ans);
    }
  }
}
0