結果

問題 No.865 24時間降水量
ユーザー bayashiko_rbayashiko_r
提出日時 2019-08-16 23:31:36
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,951 bytes
コンパイル時間 1,722 ms
コンパイル使用メモリ 110,688 KB
実行使用メモリ 43,352 KB
最終ジャッジ日時 2023-10-24 06:04:27
合計ジャッジ時間 6,873 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 29 ms
25,372 KB
testcase_19 AC 30 ms
25,372 KB
testcase_20 AC 28 ms
25,372 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program {
    static void Main(string[] args) {
        //入力
        int N = int.Parse(Console.ReadLine());
        int[] A = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        int Q = int.Parse(Console.ReadLine());
        int[] T = new int[N];
        int[] V = new int[N];

        for (int i = 0; i < Q; i++) {
            string s = Console.ReadLine();
            T[i] = int.Parse(s.Split(' ')[0]);
            V[i] = int.Parse(s.Split(' ')[1]);
        }

        int sum = 0;
        for (int i = 0; i < 24; i++) {
            sum += A[i];
        }

        //最大値(逐次変わる)
        int max = sum;

        //まずは変更なしの状態での、連続最大値を求める
        for (int i = 0; i < N - 24; i++) {
            max = Math.Max(max, max - A[i] + A[i + 24]);
        }

        //変更後の最大値を求める
        for (int i = 0; i < Q; i++) {
            //変化を起こす
            A[T[i] - 1] = V[i];

            int after_max = 0;
            //変化点が、中央に収まっているとき
            if (T[i] >= 24 && T[i] <= N - 23) {
                //左端から24個カウントした和を取る
                for (int j = T[i] - 24; j <= T[i] - 1; j++) {
                    after_max += A[j];
                }

                for (int j = T[i] - 24; j <= T[i] - 2; j++) {
                    after_max = Math.Max(after_max, after_max - A[j] + A[j + 24]);
                }
            //変化点の右端が、詰まっているとき
            } else if (T[i] >= 24) {
                //左端から24個カウントした和を取る
                for (int j = T[i] - 24; j <= T[i] - 1; j++) {
                    after_max += A[j];
                }

                for (int j = T[i] - 24; j <= N - 25; j++) {
                    after_max = Math.Max(after_max, after_max - A[j] + A[j + 24]);
                }
            //変化点の左端が、詰まっているとき
            } else if (T[i] <= N - 23) {
                for (int j = 0; j < 24; j++) {
                    after_max += A[j];
                }

                for (int j = 0; j <= T[i] - 2; j++) {
                    after_max = Math.Max(after_max, after_max - A[j] + A[j + 24]);
                }
            //変化点の両端が詰まっているとき
            } else {
                for (int j = 0; j < 24; j++) {
                    after_max += A[j];
                }

                for (int j = 0; j <= N - 25; j++) {
                    after_max = Math.Max(after_max, after_max - A[j] + A[j + 24]);
                }
            }
            //Console.WriteLine(after_max);

            max = Math.Max(max, after_max);

            //出力
            Console.WriteLine(max);

            
        }
        

    }
}
0