結果
問題 | No.1715 Dinner 2 |
ユーザー | yamake |
提出日時 | 2021-10-22 21:48:56 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 171 ms / 2,000 ms |
コード長 | 1,417 bytes |
コンパイル時間 | 1,593 ms |
コンパイル使用メモリ | 172,456 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-23 05:12:33 |
合計ジャッジ時間 | 4,146 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 38 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(long long i=0;i<n;++i) #define rep1(i,n) for(long long i=1;i<=n;++i) #define rrep(i,n) for(long long i=n-1;i>=0;--i) #define debug(output) if(debugFlag)cout<<#output<<"= "<<output<<endl using lint = long long; typedef pair<int,int> P; const bool debugFlag=true; const lint linf=1.1e18;const lint inf=1.01e9; constexpr int MOD=1000000007; template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; } signed main(){ int n,d;cin>>n>>d; vector<P> a(n); rep(i,n)cin>>a[i].first>>a[i].second; auto judge=[&](int x)->bool{ vector<int> dp(n,0); rep(i,n){ if(0-a[i].first<x)dp[i]=-inf; else dp[i]=a[i].second-a[i].first; } rep(_z,d-1){ vector<int> nxt(n,-inf); vector<int> l(n+1,-inf),r(n+1,-inf); rep1(i,n)l[i]=max(l[i-1],dp[i-1]); rrep(i,n-1)r[i]=max(r[i+1],dp[i+1]); rep(i,n){ if(l[i]-a[i].first>=x)nxt[i]=l[i]+a[i].second-a[i].first; if(r[i]-a[i].first>=x)nxt[i]=max(nxt[i],r[i]+a[i].second-a[i].first); } swap(dp,nxt); } auto it=max_element(dp.begin(),dp.end()); return *it!=-inf; }; int dd=-inf;int u=inf; while(u-dd>1){ int mid=(u+dd)/2; if(judge(mid))dd=mid; else u=mid; } cout<<dd<<"\n"; return 0; }