結果

問題 No.1375 Divide and Update
ユーザー leaf_1415leaf_1415
提出日時 2019-02-27 00:32:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 1,017 bytes
コンパイル時間 899 ms
コンパイル使用メモリ 52,628 KB
実行使用メモリ 17,616 KB
最終ジャッジ日時 2023-09-27 09:23:19
合計ジャッジ時間 5,333 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,060 KB
testcase_01 AC 2 ms
5,068 KB
testcase_02 AC 4 ms
5,064 KB
testcase_03 AC 2 ms
4,996 KB
testcase_04 AC 2 ms
5,000 KB
testcase_05 AC 2 ms
5,060 KB
testcase_06 AC 2 ms
5,060 KB
testcase_07 AC 2 ms
4,992 KB
testcase_08 AC 2 ms
4,992 KB
testcase_09 AC 1 ms
5,056 KB
testcase_10 AC 46 ms
15,712 KB
testcase_11 AC 43 ms
14,920 KB
testcase_12 AC 25 ms
9,660 KB
testcase_13 AC 21 ms
8,816 KB
testcase_14 AC 53 ms
17,368 KB
testcase_15 AC 54 ms
17,616 KB
testcase_16 AC 52 ms
17,420 KB
testcase_17 AC 51 ms
17,364 KB
testcase_18 AC 53 ms
17,400 KB
testcase_19 AC 54 ms
17,440 KB
testcase_20 AC 41 ms
17,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#define llint long long
#define inf 1e18

using namespace std;

llint n, x, y;
llint a[200005], b[200005], c[200005];
llint B[200005], C[200005];
llint minB[200005], minC[200005];
llint maxL[200005], maxR[200005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> x >> y;
	for(int i = 1; i <= n; i++) cin >> a[i];
	
	llint sum = 0;
	for(int i = 1; i <= n; i++) sum += a[i];
	for(int i = 1; i <= n; i++) b[i] = x - a[i], c[i] = y - a[i];
	
	for(int i = 1; i <= n; i++) B[i] = B[i-1] + b[i];
	for(int i = n; i >= 1; i--) C[i] = C[i+1] + c[i];
	
	minB[0] = 0;
	for(int i = 1; i <= n; i++) minB[i] = min(minB[i-1], B[i]);
	minC[n+1] = 0;
	for(int i = n; i >= 1; i--) minC[i] = min(minC[i+1], C[i]);
	
	maxL[0] = maxR[n+1] = -inf;
	for(int i = 1; i < n; i++) maxL[i] = max(maxL[i-1], B[i]-minB[i-1]);
	for(int i = n; i > 1; i--) maxR[i] = max(maxR[i+1], C[i]-minC[i+1]);
	
	for(int i = 2; i < n; i++){
		cout << sum + maxL[i-1] + maxR[i+1] << "\n";
	}
	flush(cout);
	
	return 0;
}
0