結果

問題 No.1375 Divide and Update
ユーザー kk
提出日時 2021-02-08 22:43:17
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 290 ms / 2,000 ms
コード長 831 bytes
コンパイル時間 2,244 ms
コンパイル使用メモリ 200,944 KB
実行使用メモリ 7,232 KB
最終ジャッジ日時 2023-09-20 07:18:38
合計ジャッジ時間 8,972 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 248 ms
6,428 KB
testcase_11 AC 224 ms
6,184 KB
testcase_12 AC 125 ms
4,572 KB
testcase_13 AC 104 ms
4,376 KB
testcase_14 AC 282 ms
6,952 KB
testcase_15 AC 290 ms
6,936 KB
testcase_16 AC 281 ms
7,040 KB
testcase_17 AC 289 ms
6,952 KB
testcase_18 AC 284 ms
7,004 KB
testcase_19 AC 287 ms
7,232 KB
testcase_20 AC 275 ms
6,956 KB
権限があれば一括ダウンロードができます

ソースコード

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