結果

問題 No.1715 Dinner 2
ユーザー ぷらぷら
提出日時 2021-10-22 21:32:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 188 ms / 2,000 ms
コード長 1,125 bytes
コンパイル時間 3,894 ms
コンパイル使用メモリ 207,428 KB
実行使用メモリ 7,376 KB
最終ジャッジ日時 2023-10-24 12:26:21
合計ジャッジ時間 4,941 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 145 ms
6,444 KB
testcase_12 AC 118 ms
5,916 KB
testcase_13 AC 99 ms
5,388 KB
testcase_14 AC 115 ms
5,916 KB
testcase_15 AC 120 ms
5,916 KB
testcase_16 AC 111 ms
5,652 KB
testcase_17 AC 72 ms
4,860 KB
testcase_18 AC 4 ms
4,348 KB
testcase_19 AC 6 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 13 ms
4,348 KB
testcase_26 AC 9 ms
4,348 KB
testcase_27 AC 9 ms
4,348 KB
testcase_28 AC 13 ms
4,348 KB
testcase_29 AC 13 ms
4,348 KB
testcase_30 AC 13 ms
4,348 KB
testcase_31 AC 13 ms
4,348 KB
testcase_32 AC 185 ms
7,376 KB
testcase_33 AC 187 ms
7,376 KB
testcase_34 AC 188 ms
7,376 KB
testcase_35 AC 186 ms
7,376 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 6 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    int N,D;
    cin >> N >> D;
    vector<int>P(N),Q(N);
    for(int i = 0; i < N; i++) {
        cin >> P[i] >> Q[i];
    }
    int l = -1001001001,r = 0;
    while (l+1 < r) {
        int mid = (l+r)/2;
        vector<vector<int>>dp(D+1,vector<int>(N,-1001001001));
        for(int i = 0; i < N; i++) {
            dp[0][i] = 0;
        }
        for(int i = 0; i < D; i++) {
            vector<int>lmx(N+1,-1001001001),rmx(N+1,-1001001001);
            for(int j = 0; j < N; j++) {
                lmx[j+1] = max(lmx[j],dp[i][j]);
            }
            for(int j = N; j >= 1; j--) {
                rmx[j-1] = max(rmx[j],dp[i][j-1]);
            }
            for(int j = 0; j < N; j++) {
                if(max(lmx[j],rmx[j+1])-P[j] >= mid) {
                    dp[i+1][j] = max(dp[i+1][j],max(lmx[j],rmx[j+1])-P[j]+Q[j]);
                }
            }
        }
        int mx = *max_element(dp[D].begin(),dp[D].end());
        if(mx >= mid) {
            l = mid;
        }
        else {
            r = mid;
        }
    }
    cout << l << endl;
}
0