結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2020-06-04 13:02:56
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 160 ms / 2,000 ms
コード長 1,801 bytes
コンパイル時間 1,643 ms
コンパイル使用メモリ 151,852 KB
実行使用メモリ 6,336 KB
最終ジャッジ日時 2023-08-19 03:27:42
合計ジャッジ時間 8,382 ms
ジャッジサーバーID
(参考情報)
judge12 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 3 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,388 KB
testcase_13 AC 23 ms
4,380 KB
testcase_14 AC 25 ms
4,380 KB
testcase_15 AC 63 ms
4,612 KB
testcase_16 AC 105 ms
5,248 KB
testcase_17 AC 108 ms
5,112 KB
testcase_18 AC 19 ms
4,380 KB
testcase_19 AC 145 ms
6,036 KB
testcase_20 AC 51 ms
4,384 KB
testcase_21 AC 142 ms
5,876 KB
testcase_22 AC 53 ms
4,380 KB
testcase_23 AC 143 ms
6,052 KB
testcase_24 AC 36 ms
4,380 KB
testcase_25 AC 144 ms
5,852 KB
testcase_26 AC 18 ms
4,384 KB
testcase_27 AC 106 ms
5,252 KB
testcase_28 AC 100 ms
4,796 KB
testcase_29 AC 57 ms
4,380 KB
testcase_30 AC 148 ms
5,864 KB
testcase_31 AC 22 ms
4,380 KB
testcase_32 AC 24 ms
4,380 KB
testcase_33 AC 159 ms
6,248 KB
testcase_34 AC 151 ms
6,300 KB
testcase_35 AC 160 ms
6,172 KB
testcase_36 AC 154 ms
6,248 KB
testcase_37 AC 157 ms
6,332 KB
testcase_38 AC 154 ms
6,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.06.04 13:02:39
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

int n, k;
// x以下のものを自分でするときにできるか
bool f(int x, const vector< pair< int, int > >& a) {
    int pre = -1000000000;
    for (int i = 0; i < n; i++) {
        if (x < a[i].second) {
            if (a[i].first - pre >= k) {
                pre = a[i].first;
            } else {
                return false;
            }
        }
    }
    return true;
}
int main() {
    cin >> n >> k;
    vector< pair< int, int > > a(n);
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i].first >> a[i].second;
        sum += a[i].second;
    }
    int l = -1, r = 1000000000;
    while (r - l > 1) {
        int mid = l + (r - l) / 2;
        if (f(mid, a)) {
            r = mid;
        } else {
            l = mid;
        }
    }
    cout << r << endl;
    vector< bool > aaa(n, false);
    ll prev = 1000000000000000;
    for (int i = n - 1; i >= 0; i--) {
        if (prev - a[i].first < k) {
            aaa[i] = true;
        } else if (a[i].second > r) {
            prev = a[i].first;
        }
    }
    constexpr long long LLINF = 1e18 + 1;
    vector< ll > dp(n, 0);
    dp[n - 1] = a[n - 1].second;
    for (int i = n - 2; i >= 0; i--) {
        // 飛ばす
        if (!aaa[i]) {
            auto p = lower_bound(a.begin(), a.end(), make_pair(a[i].first + k, -1));
            if (p != a.end()) {
                dp[i] = max(dp[i], dp[p - a.begin()] + a[i].second);
            } else {
                dp[i] = a[i].second;
            }
        }
        if (r >= a[i].second) {
            dp[i] = max(dp[i], dp[i + 1]);
        }
    }
    cout << sum - dp[0] << endl;
    return 0;
}
0