結果

問題 No.818 Dinner time
ユーザー okok
提出日時 2019-04-19 23:07:09
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,261 bytes
コンパイル時間 679 ms
コンパイル使用メモリ 71,844 KB
実行使用メモリ 8,368 KB
最終ジャッジ日時 2023-10-24 11:42:14
合計ジャッジ時間 2,395 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX 110000

int N, M;
int a, b;
int A[MAX], B[MAX];
int hoge[MAX][4] = {};
signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int ans = 0, temp, num = 0;
	
	
	cin>>N>>M;
	
	// hoge[0][0] = -INF;
	
	for(int i = 0; i < N; i++){
		cin>>a>>b;
		
		if(a >= 0 && b >= 0){
			if(a >= b) temp = a*M;
			else temp = a*(M-1)+b;
		} else if(a >= 0 && b < 0){
			temp = a*M;
		} else if(a < 0 && b >= 0){
			temp = b;
		} else {
			if(b >= a*M){
				temp = b;
			} else {
				temp = a*M;
			}
		}
		hoge[i+1][2] += temp+hoge[i][2];
		
		hoge[i+1][1] = max(hoge[i][2],hoge[i][1]) + max(a,b);
		
		if(i)hoge[i+1][0] = max(hoge[i][0],max(hoge[i][2],hoge[i][1]));
		else hoge[i+1][0] = -INF;
		
		// cout<<temp<<" "<<max(a,b)<<endl;
		// cout<<hoge[i+1][0]<<" "<<hoge[i+1][1]<<" "<<hoge[i+1][2]<<endl;
	}
	
	ans = max(hoge[N][0],max(hoge[N][2],hoge[N][1]));
	
	cout<<ans<<endl;
	
	return 0;
}
0