結果
| 問題 |
No.1375 Divide and Update
|
| コンテスト | |
| ユーザー |
ninoinui
|
| 提出日時 | 2021-02-05 23:02:14 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 56 ms / 2,000 ms |
| コード長 | 1,023 bytes |
| コンパイル時間 | 2,937 ms |
| コンパイル使用メモリ | 195,212 KB |
| 最終ジャッジ日時 | 2025-01-18 12:54:30 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 19 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
template <class A, class B> bool cmin(A& a, B b) { return a > b && (a = b, true); }
template <class A, class B> bool cmax(A& a, B b) { return a < b && (a = b, true); }
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
long N, X, Y;
cin >> N >> X >> Y;
vector<long> A(N);
for (long i = 0; i < N; i++) cin >> A.at(i);
auto B = A;
for (long i = 0; i < N; i++) {
B.at(i) = X - B.at(i);
}
vector<long> L(N);
for (long i = 0, now = 0, mx = LONG_MIN; i < N; i++) {
now += B.at(i);
cmax(mx, now);
if (now < 0) now = 0;
L.at(i) = mx;
}
auto C = A;
for (long i = 0; i < N; i++) {
C.at(i) = Y - C.at(i);
}
vector<long> R(N);
for (long i = N - 1, now = 0, mx = LONG_MIN; i >= 0; i--) {
now += C.at(i);
cmax(mx, now);
if (now < 0) now = 0;
R.at(i) = mx;
}
long acc = accumulate(A.begin(), A.end(), 0L);
for (long i = 1; i + 1 < N; i++) {
cout << acc + L.at(i - 1) + R.at(i + 1) << '\n';
}
}
ninoinui