結果
| 問題 |
No.865 24時間降水量
|
| コンテスト | |
| ユーザー |
bayashiko_r
|
| 提出日時 | 2019-08-16 23:31:36 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,951 bytes |
| コンパイル時間 | 2,293 ms |
| コンパイル使用メモリ | 114,676 KB |
| 実行使用メモリ | 37,504 KB |
| 最終ジャッジ日時 | 2024-09-22 22:54:27 |
| 合計ジャッジ時間 | 7,510 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | WA * 13 RE * 5 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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);
}
}
}
bayashiko_r