結果

問題 No.818 Dinner time
ユーザー ahe100ahe100
提出日時 2019-04-20 01:33:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 759 bytes
コンパイル時間 1,510 ms
コンパイル使用メモリ 167,528 KB
実行使用メモリ 7,448 KB
最終ジャッジ日時 2023-10-24 22:53:58
合計ジャッジ時間 4,694 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,680 KB
testcase_01 AC 2 ms
5,680 KB
testcase_02 AC 3 ms
5,680 KB
testcase_03 AC 2 ms
5,680 KB
testcase_04 WA -
testcase_05 AC 2 ms
5,680 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
5,680 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 2 ms
5,680 KB
testcase_15 AC 2 ms
5,680 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

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];
	rep(j,3)dp[0][j]=0;
}

int main(void){
	init();
	reg(i,1,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])+(a[i]<b[i]?b[i]:a[i]);
		dp[i][2]=dp[i-1][2]+a[i]*(m-1)+(a[i]<b[i]?b[i]:a[i]);
	}
	cout<<max({dp[n][0],dp[n][1],dp[n][2]})<<endl;
	return 0;
}
0