結果

問題 No.1715 Dinner 2
ユーザー cureskolcureskol
提出日時 2021-10-22 21:39:34
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 924 bytes
コンパイル時間 1,939 ms
コンパイル使用メモリ 181,792 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 12:38:31
合計ジャッジ時間 3,880 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 1 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 1 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 76 ms
4,348 KB
testcase_12 AC 62 ms
4,348 KB
testcase_13 AC 50 ms
4,348 KB
testcase_14 AC 62 ms
4,348 KB
testcase_15 AC 62 ms
4,348 KB
testcase_16 AC 60 ms
4,348 KB
testcase_17 AC 38 ms
4,348 KB
testcase_18 AC 4 ms
4,348 KB
testcase_19 AC 4 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 11 ms
4,348 KB
testcase_26 AC 8 ms
4,348 KB
testcase_27 AC 8 ms
4,348 KB
testcase_28 AC 10 ms
4,348 KB
testcase_29 AC 10 ms
4,348 KB
testcase_30 AC 10 ms
4,348 KB
testcase_31 AC 10 ms
4,348 KB
testcase_32 AC 95 ms
4,348 KB
testcase_33 AC 95 ms
4,348 KB
testcase_34 AC 97 ms
4,348 KB
testcase_35 AC 97 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 4 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n-1);i>=0;i--)
#define ALL(v) v.begin(),v.end()

const int INF=1e9+7;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,d;cin>>n>>d;
  vector<int> p(n),q(n);
  REP(i,n)cin>>p[i]>>q[i];
  int ok=-INF,ng=INF;
  while(ng-ok>1){
    int mid=(ok+ng)>>1;
    vector<int> dp(n+1,-INF);
    dp[n]=0;
    REP(_,d){
      vector<int> mx(n+2),mx2(n+2);
      mx[0]=-INF;
      REP(i,n+1)mx[i+1]=max(mx[i],dp[i]);
      mx2.back()=-INF;
      for(int i=n;i>=0;i--)mx2[i]=max(mx2[i+1],dp[i]);
      vector<int> cpy(n+1,-INF);
      REP(i,n){
        int pre=max(mx[i],mx2[i+1]);
        if(pre-p[i]>=mid)cpy[i]=pre-p[i]+q[i];
      }
      dp=cpy;
    }
    bool fok=false;
    REP(i,n)if(dp[i]>-INF)fok=true;
    if(fok)ok=mid;
    else ng=mid;
  }
  cout<<ok<<endl;
}
0