結果

問題 No.818 Dinner time
コンテスト
ユーザー vjudge1
提出日時 2026-08-29 17:43:34
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 938 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,285 ms
コンパイル使用メモリ 210,464 KB
実行使用メモリ 7,296 KB
最終ジャッジ日時 2026-08-29 17:43:40
合計ジャッジ時間 3,233 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
#define eb emplace_back
#define ls i<<1
#define rs i<<1|1
using namespace std;
using ll=long long;
using pii=pair<ll,ll>;
constexpr int N=1e5+10,M=1e5+10,K=1e5+10,L=20;
constexpr ll INF=0x3f3f3f3f3f3f3f3f;
constexpr int inf=0x3f3f3f3f;
constexpr int mod=1e9+7;
constexpr long double pi=acos(-1);
constexpr double eps=1e-11;
ll T,n,a[N],b[N],m,sumn[N],ans=-INF,maxn[N],dp[N];
void solve(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i]>>b[i];
		sumn[i]=sumn[i-1]+max(a[i],b[i]);
	}
	for(int i=1;i<=n;i++) maxn[i]=-inf;
	for(int i=n;i>=1;i--){
		maxn[i]=max(maxn[i+1],sumn[i]);
	}
	for(int i=1;i<=n;i++){
		dp[i]=max({b[i],a[i]*m,a[i]*(m-1)+b[i]})+dp[i-1];
		ans=max({ans,dp[i]+maxn[i+1]-sumn[i],dp[i]});
	}
	cout<<ans;
	return;
}
int main(){
	ios::sync_with_stdio(false);
//	freopen("remake.in","r",stdin);
	cin.tie(nullptr);
//	freopen("remake.out","w",stdout);
	T=1;
//	cin>>T;
	while(T--) solve();
	return 0;
}
0