結果

問題 No.865 24時間降水量
ユーザー lemty
提出日時 2019-08-17 00:36:51
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 426 ms / 2,000 ms
コード長 932 bytes
コンパイル時間 2,151 ms
コンパイル使用メモリ 198,844 KB
最終ジャッジ日時 2025-01-07 13:09:53
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long int;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &x : a)
    cin >> x;
  vector<int> b(n);

  int sum = 0;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (i < 24)
      sum += a[i];
    else
      sum += a[i] - a[i - 24];
    ans = max(ans, sum);
  }

  int q;
  cin >> q;
  vector<pair<int, int>> queries;
  for (int i = 0; i < q; i++) {
    int t, v;
    cin >> t >> v;
    t--;
    queries.push_back({t, v});
  }
  for (auto query : queries) {
    int t = query.first;
    int v = query.second;
    a[t] = v;
    for (int i = -23; i <= 0; i++) {
      sum = 0;
      for (int j = 0; j <= 23; j++) {
        int index = t + i + j;
        if (0 <= index && index < n)
          sum += a[index];
      }
      ans = max(ans, sum);
    }
    cout << ans << endl;
  }

  return 0;
}
0