結果

問題 No.818 Dinner time
ユーザー leaf_1415leaf_1415
提出日時 2019-04-19 22:07:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 564 bytes
コンパイル時間 444 ms
コンパイル使用メモリ 52,396 KB
実行使用メモリ 6,308 KB
最終ジャッジ日時 2023-08-20 00:46:19
合計ジャッジ時間 2,569 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 48 ms
6,308 KB
testcase_18 AC 34 ms
5,264 KB
testcase_19 AC 37 ms
5,300 KB
testcase_20 AC 49 ms
6,152 KB
testcase_21 AC 44 ms
5,652 KB
testcase_22 AC 33 ms
5,088 KB
testcase_23 AC 39 ms
5,376 KB
testcase_24 AC 56 ms
6,288 KB
testcase_25 AC 39 ms
5,364 KB
testcase_26 AC 32 ms
5,260 KB
testcase_27 AC 49 ms
5,896 KB
testcase_28 AC 40 ms
5,432 KB
testcase_29 AC 52 ms
6,208 KB
testcase_30 AC 45 ms
5,764 KB
testcase_31 AC 49 ms
5,972 KB
testcase_32 AC 40 ms
5,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#define llint long long

using namespace std;

llint n, m;
llint a[100005], b[100005];
llint s[100005], mn[100005];

int main(void)
{
	cin >> n >> m;
	for(int i = 1; i <= n; i++) cin >> a[i] >> b[i];
	
	for(int i = n; i >= 1; i--) s[i] = s[i+1] + max(a[i], b[i]);
	for(int i = n; i >= 1; i--) mn[i] = min(s[i], mn[i+1]);
	
	llint ans = -1e18, sum = 0;
	for(int i = 1; i <= n; i++){
		if(a[i] >= 0) sum += a[i]*(m-1)+max(a[i],b[i]);
		else sum += max(a[i]*m, b[i]);
		ans = max(ans, sum + s[i+1]-mn[i+1]);
	}
	cout << ans << endl;
	
	return 0;
}
0