結果

問題 No.818 Dinner time
ユーザー 沙耶花沙耶花
提出日時 2020-12-08 17:45:01
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 597 bytes
コンパイル時間 2,135 ms
コンパイル使用メモリ 207,028 KB
実行使用メモリ 9,992 KB
最終ジャッジ日時 2023-10-17 18:07:30
合計ジャッジ時間 5,661 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 28 ms
9,992 KB
testcase_18 AC 19 ms
7,616 KB
testcase_19 AC 20 ms
7,880 KB
testcase_20 AC 27 ms
9,464 KB
testcase_21 AC 23 ms
8,672 KB
testcase_22 AC 19 ms
7,352 KB
testcase_23 AC 22 ms
7,880 KB
testcase_24 AC 30 ms
9,992 KB
testcase_25 AC 21 ms
7,880 KB
testcase_26 AC 19 ms
7,088 KB
testcase_27 AC 27 ms
9,200 KB
testcase_28 AC 22 ms
8,144 KB
testcase_29 AC 28 ms
9,660 KB
testcase_30 AC 24 ms
8,672 KB
testcase_31 AC 26 ms
8,936 KB
testcase_32 AC 21 ms
8,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000000000000

int main(){
	
	int N,M;
	cin>>N>>M;
	
	vector<long long> A(N),B(N);
	rep(i,N)scanf("%lld %lld",&A[i],&B[i]);
	
	vector dp(N,vector<long long>(2,-Inf));
	
	dp[0][0] = max({B[0],A[0]*M,A[0]*(M-1)+B[0]});
	
	for(int i=1;i<N;i++){
		dp[i][0] = dp[i-1][0] + max({B[i],A[i]*M,A[i]*(M-1)+B[i]});
		
		dp[i][1] = max(dp[i-1][0],dp[i-1][1]) + max(A[i],B[i]);
	}
	
	long long ans = -Inf;
	rep(i,N){
		rep(j,2){
			ans = max(ans,dp[i][j]);
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
}
0