結果

問題 No.1715 Dinner 2
ユーザー didi just isdidi just is
提出日時 2023-04-14 23:07:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 1,453 bytes
コンパイル時間 1,539 ms
コンパイル使用メモリ 163,304 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-04-18 20:43:48
合計ジャッジ時間 3,667 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 78 ms
11,264 KB
testcase_12 AC 59 ms
9,216 KB
testcase_13 AC 52 ms
8,064 KB
testcase_14 AC 63 ms
9,600 KB
testcase_15 AC 62 ms
9,216 KB
testcase_16 AC 57 ms
10,240 KB
testcase_17 AC 41 ms
8,960 KB
testcase_18 AC 3 ms
5,760 KB
testcase_19 AC 4 ms
7,424 KB
testcase_20 AC 4 ms
6,784 KB
testcase_21 AC 3 ms
6,272 KB
testcase_22 AC 4 ms
6,528 KB
testcase_23 AC 4 ms
7,168 KB
testcase_24 AC 3 ms
6,528 KB
testcase_25 AC 10 ms
7,680 KB
testcase_26 AC 9 ms
6,912 KB
testcase_27 AC 8 ms
6,400 KB
testcase_28 AC 11 ms
7,936 KB
testcase_29 AC 10 ms
7,936 KB
testcase_30 AC 10 ms
7,808 KB
testcase_31 AC 12 ms
7,680 KB
testcase_32 AC 93 ms
11,392 KB
testcase_33 AC 96 ms
11,520 KB
testcase_34 AC 91 ms
11,392 KB
testcase_35 AC 97 ms
11,520 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 4 ms
7,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e3+10,INF=1e10;
int n,m;
int a[N],b[N];
int dp[N][N];
int l[N],r[N];
bool check(int mid){
    for(int i=1;i<=n;i++){
        if(-a[i]>=mid){
            dp[1][i]=-a[i]+b[i];
        }
        else{
            dp[1][i]=-INF;
        }
        //if(mid==-4) cout<<dp[1][i]<<' ';
    }
    //if(mid==-4) cout<<endl;
    l[0]=r[n+1]=-INF;
    for(int j=1;j<=n;j++){
        l[j]=max(l[j-1],dp[1][j]);
    }
    for(int j=n;j>=1;j--){
        r[j]=max(r[j+1],dp[1][j]);
    }
    for(int i=2;i<=m;i++){
        for(int j=1;j<=n;j++){
            int ma=max(l[j-1],r[j+1]);
            if(ma-a[j]>=mid){
                dp[i][j]=ma-a[j]+b[j];
            }
            else{
                dp[i][j]=-INF;
            }
            //if(mid==-4) cout<<dp[i][j]<<' ';
        }
        //if(mid==-4) cout<<endl;
        l[0]=r[n+1]=-INF;
        for(int j=1;j<=n;j++){
            l[j]=max(l[j-1],dp[i][j]);
        }
        for(int j=n;j>=1;j--){
            r[j]=max(r[j+1],dp[i][j]);
        }
    }
    for(int i=1;i<=n;i++){
        if(dp[m][i]!=-INF) return 1;
    }
    return 0;
}
signed main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++) cin>>a[i]>>b[i];
    //for(int i=1;i<=n;i++) cin>>b[i];

    int ll=-INF,rr=INF,ans=ll;
    while(ll<=rr){
        int mid=ll+rr>>1;
        if(check(mid)) ans=mid,ll=mid+1;
        else rr=mid-1;
    }
    cout<<ans;
    return 0;
}
0