結果

問題 No.818 Dinner time
ユーザー leaf_1415leaf_1415
提出日時 2019-04-19 22:07:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 564 bytes
コンパイル時間 598 ms
コンパイル使用メモリ 56,008 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-07 08:13:30
合計ジャッジ時間 2,428 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 48 ms
6,940 KB
testcase_18 AC 36 ms
6,940 KB
testcase_19 AC 39 ms
6,940 KB
testcase_20 AC 49 ms
6,940 KB
testcase_21 AC 46 ms
6,940 KB
testcase_22 AC 37 ms
6,944 KB
testcase_23 AC 41 ms
6,940 KB
testcase_24 AC 60 ms
6,940 KB
testcase_25 AC 42 ms
6,944 KB
testcase_26 AC 35 ms
6,944 KB
testcase_27 AC 53 ms
6,940 KB
testcase_28 AC 44 ms
6,940 KB
testcase_29 AC 55 ms
6,944 KB
testcase_30 AC 47 ms
6,944 KB
testcase_31 AC 50 ms
6,944 KB
testcase_32 AC 41 ms
6,944 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