結果

問題 No.818 Dinner time
ユーザー pockynypockyny
提出日時 2019-04-20 15:28:39
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 496 bytes
コンパイル時間 567 ms
コンパイル使用メモリ 71,296 KB
実行使用メモリ 6,304 KB
最終ジャッジ日時 2023-08-20 00:57:33
合計ジャッジ時間 2,593 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 49 ms
6,232 KB
testcase_18 AC 34 ms
5,252 KB
testcase_19 AC 37 ms
5,604 KB
testcase_20 AC 48 ms
6,060 KB
testcase_21 AC 43 ms
5,696 KB
testcase_22 AC 34 ms
5,096 KB
testcase_23 AC 39 ms
5,380 KB
testcase_24 AC 55 ms
6,304 KB
testcase_25 AC 38 ms
5,336 KB
testcase_26 AC 33 ms
5,276 KB
testcase_27 AC 48 ms
5,964 KB
testcase_28 AC 40 ms
5,732 KB
testcase_29 AC 52 ms
6,184 KB
testcase_30 AC 45 ms
5,684 KB
testcase_31 AC 48 ms
5,924 KB
testcase_32 AC 40 ms
5,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>

using namespace std;
typedef long long ll;
ll dp[100010][2] = {},a[100010],b[100010];
int main(){
	ll i,n,m;
	cin >> n >> m;
	for(i=0;i<n;i++){
		cin >> a[i] >> b[i];
	}
	dp[n-1][0] = max(a[n-1],b[n-1]);
	dp[n-1][1] = max({(m-1)*a[n-1] + b[n-1],m*a[n-1],b[n-1]});
	for(i=n-2;i>=0;i--){
		dp[i][0] = max(dp[i+1][0],0LL) + max(a[i],b[i]);
		dp[i][1] = max({dp[i+1][0],dp[i+1][1],0LL}) + max({(m-1)*a[i] + b[i],m*a[i],b[i]});
	}
	cout << dp[0][1] << endl;
}
0