結果

問題 No.818 Dinner time
ユーザー leaf_1415leaf_1415
提出日時 2019-04-19 22:07:53
言語 C++11
(gcc 8.5.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 564 bytes
コンパイル時間 301 ms
使用メモリ 6,952 KB
最終ジャッジ日時 2023-01-06 05:10:38
合計ジャッジ時間 2,534 ms
ジャッジサーバーID
(参考情報)
judge16 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 1 ms
4,900 KB
testcase_01 AC 1 ms
6,948 KB
testcase_02 AC 1 ms
4,900 KB
testcase_03 AC 1 ms
6,952 KB
testcase_04 AC 1 ms
4,900 KB
testcase_05 AC 2 ms
6,948 KB
testcase_06 AC 1 ms
4,904 KB
testcase_07 AC 2 ms
6,952 KB
testcase_08 AC 1 ms
4,904 KB
testcase_09 AC 1 ms
4,904 KB
testcase_10 AC 2 ms
4,904 KB
testcase_11 AC 1 ms
6,948 KB
testcase_12 AC 1 ms
6,948 KB
testcase_13 AC 1 ms
4,904 KB
testcase_14 AC 1 ms
4,904 KB
testcase_15 AC 1 ms
4,904 KB
testcase_16 AC 2 ms
4,904 KB
testcase_17 AC 47 ms
6,292 KB
testcase_18 AC 32 ms
5,428 KB
testcase_19 AC 35 ms
5,512 KB
testcase_20 AC 46 ms
6,948 KB
testcase_21 AC 42 ms
5,760 KB
testcase_22 AC 33 ms
6,952 KB
testcase_23 AC 38 ms
5,484 KB
testcase_24 AC 54 ms
6,328 KB
testcase_25 AC 38 ms
5,452 KB
testcase_26 AC 31 ms
6,948 KB
testcase_27 AC 47 ms
6,076 KB
testcase_28 AC 39 ms
6,948 KB
testcase_29 AC 51 ms
6,304 KB
testcase_30 AC 43 ms
5,780 KB
testcase_31 AC 47 ms
5,904 KB
testcase_32 AC 39 ms
6,948 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