結果

問題 No.1375 Divide and Update
ユーザー k
提出日時 2021-02-08 22:43:17
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 315 ms / 2,000 ms
コード長 831 bytes
コンパイル時間 2,765 ms
コンパイル使用メモリ 195,724 KB
最終ジャッジ日時 2025-01-18 16:28:46
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, x, y;
  cin >> n >> x >> y;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];

  long long acc;
  vector<long long> pref(n);
  acc = x - a[0];
  pref[1] = acc;

  for (int i = 2; i < n; i++) {
    if (acc < 0) acc = x - a[i-1];
    else acc += x - a[i-1];
    pref[i] = max(pref[i-1], acc);
  }

  vector<long long> suff(n);
  acc = y - a[n-1];
  suff[n-2] = acc;

  for (int i = n-3; i >= 0; i--) {
    if (acc < 0) acc = y - a[i+1];
    else acc += y - a[i+1];
    suff[i] = max(suff[i+1], acc);
  }

  long long sum = 0;
  for (int i = 0; i < n; i++)
    sum += a[i];

  for (int i = 1; i < n-1; i++) {
    long long ret = sum + pref[i] + suff[i];
    cout << ret << endl;
  }
  
  return 0;
}
0