結果

問題 No.1715 Dinner 2
ユーザー yamakeyamake
提出日時 2021-10-22 21:48:56
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 172 ms / 2,000 ms
コード長 1,417 bytes
コンパイル時間 2,126 ms
コンパイル使用メモリ 172,804 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 12:52:08
合計ジャッジ時間 4,247 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
4,348 KB
testcase_06 AC 1 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 135 ms
4,348 KB
testcase_12 AC 110 ms
4,348 KB
testcase_13 AC 91 ms
4,348 KB
testcase_14 AC 109 ms
4,348 KB
testcase_15 AC 112 ms
4,348 KB
testcase_16 AC 107 ms
4,348 KB
testcase_17 AC 66 ms
4,348 KB
testcase_18 AC 4 ms
4,348 KB
testcase_19 AC 5 ms
4,348 KB
testcase_20 AC 4 ms
4,348 KB
testcase_21 AC 4 ms
4,348 KB
testcase_22 AC 4 ms
4,348 KB
testcase_23 AC 5 ms
4,348 KB
testcase_24 AC 4 ms
4,348 KB
testcase_25 AC 16 ms
4,348 KB
testcase_26 AC 11 ms
4,348 KB
testcase_27 AC 11 ms
4,348 KB
testcase_28 AC 14 ms
4,348 KB
testcase_29 AC 15 ms
4,348 KB
testcase_30 AC 14 ms
4,348 KB
testcase_31 AC 16 ms
4,348 KB
testcase_32 AC 169 ms
4,348 KB
testcase_33 AC 165 ms
4,348 KB
testcase_34 AC 172 ms
4,348 KB
testcase_35 AC 172 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 1 ms
4,348 KB
testcase_38 AC 4 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0