結果

問題 No.865 24時間降水量
ユーザー ks2mks2m
提出日時 2019-08-16 22:12:16
言語 Java17
(openjdk 17.0.1)
結果
AC  
実行時間 643 ms / 2,000 ms
コード長 1,236 bytes
コンパイル時間 1,696 ms
使用メモリ 76,268 KB
最終ジャッジ日時 2022-11-22 07:02:11
合計ジャッジ時間 7,137 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 53 ms
48,584 KB
testcase_01 AC 53 ms
49,844 KB
testcase_02 AC 52 ms
49,688 KB
testcase_03 AC 55 ms
49,620 KB
testcase_04 AC 54 ms
49,640 KB
testcase_05 AC 84 ms
48,772 KB
testcase_06 AC 85 ms
49,036 KB
testcase_07 AC 82 ms
48,760 KB
testcase_08 AC 82 ms
49,020 KB
testcase_09 AC 84 ms
48,888 KB
testcase_10 AC 187 ms
54,128 KB
testcase_11 AC 190 ms
54,020 KB
testcase_12 AC 186 ms
53,992 KB
testcase_13 AC 185 ms
53,968 KB
testcase_14 AC 192 ms
53,964 KB
testcase_15 AC 643 ms
76,268 KB
testcase_16 AC 614 ms
74,368 KB
testcase_17 AC 590 ms
76,196 KB
testcase_18 AC 50 ms
49,632 KB
testcase_19 AC 51 ms
48,516 KB
testcase_20 AC 54 ms
49,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		int q = Integer.parseInt(br.readLine());
		int[] t = new int[q];
		int[] v = new int[q];
		for (int i = 0; i < q; i++) {
			sa = br.readLine().split(" ");
			t[i] = Integer.parseInt(sa[0]) - 1;
			v[i] = Integer.parseInt(sa[1]);
		}
		br.close();

		int[] b = new int[n];
		int sum = 0;
		for (int i = 0; i < 24; i++) {
			sum += a[i];
		}
		b[23] = sum;
		for (int i = 24; i < n; i++) {
			sum -= a[i - 24];
			sum += a[i];
			b[i] = sum;
		}

		int max = 0;
		for (int i = 23; i < n; i++) {
			max = Math.max(max, b[i]);
		}

		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < q; i++) {
			int d = v[i] - a[t[i]];
			a[t[i]] = v[i];
			for (int j = t[i]; j < Math.min(t[i] + 24, n); j++) {
				b[j] += d;
				max = Math.max(max, b[j]);
			}
			pw.println(max);
		}
		pw.flush();
	}
}
0