結果

問題 No.818 Dinner time
ユーザー ahe100ahe100
提出日時 2019-04-20 01:40:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 893 bytes
コンパイル時間 1,672 ms
コンパイル使用メモリ 166,232 KB
実行使用メモリ 7,064 KB
最終ジャッジ日時 2023-08-20 00:52:04
合計ジャッジ時間 3,881 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 48 ms
7,064 KB
testcase_18 AC 34 ms
5,708 KB
testcase_19 AC 37 ms
5,788 KB
testcase_20 AC 48 ms
6,828 KB
testcase_21 AC 44 ms
6,304 KB
testcase_22 AC 33 ms
5,496 KB
testcase_23 AC 40 ms
5,896 KB
testcase_24 AC 56 ms
7,032 KB
testcase_25 AC 38 ms
5,852 KB
testcase_26 AC 33 ms
5,460 KB
testcase_27 AC 49 ms
6,524 KB
testcase_28 AC 40 ms
6,092 KB
testcase_29 AC 53 ms
6,896 KB
testcase_30 AC 45 ms
6,288 KB
testcase_31 AC 48 ms
6,468 KB
testcase_32 AC 40 ms
6,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;

/*
dp(i,j) = i番目をj個使う
実はjは0 or 1 or Mに限られる
*/

ll n,m,a[100010],b[100010],dp[100010][3];

void init(){
	cin>>n>>m;
	reg(i,1,n)cin>>a[i]>>b[i];
}

int main(void){
	init();
	//最初だけは必ず1回以上取らなければいけない。
	dp[1][0]=-1e18;//不可能
	dp[1][1]=b[1];
	dp[1][2]=max({a[1]*m,a[1]*(m-1)+b[1],b[1]});
	reg(i,2,n){
		dp[i][0]=max({dp[i-1][0],dp[i-1][1],dp[i-1][2]});
		dp[i][1]=max(dp[i-1][1],dp[i-1][2])+max(a[i],b[i]);
		dp[i][2]=dp[i-1][2]+max({a[i]*m,a[i]*(m-1)+b[i],b[i]});
	}
	cout<<max({dp[n][0],dp[n][1],dp[n][2]})<<endl;
	return 0;
}
0