結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー kimiyukikimiyuki
提出日時 2016-11-19 00:23:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 219 ms / 2,000 ms
コード長 1,668 bytes
コンパイル時間 782 ms
コンパイル使用メモリ 79,668 KB
実行使用メモリ 10,644 KB
最終ジャッジ日時 2023-09-02 12:53:33
合計ジャッジ時間 6,052 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 31 ms
4,380 KB
testcase_14 AC 31 ms
4,380 KB
testcase_15 AC 84 ms
5,480 KB
testcase_16 AC 152 ms
7,336 KB
testcase_17 AC 138 ms
7,848 KB
testcase_18 AC 23 ms
4,376 KB
testcase_19 AC 199 ms
8,824 KB
testcase_20 AC 67 ms
5,148 KB
testcase_21 AC 195 ms
8,932 KB
testcase_22 AC 72 ms
5,392 KB
testcase_23 AC 191 ms
9,664 KB
testcase_24 AC 47 ms
4,548 KB
testcase_25 AC 187 ms
8,764 KB
testcase_26 AC 22 ms
4,376 KB
testcase_27 AC 147 ms
7,524 KB
testcase_28 AC 135 ms
7,136 KB
testcase_29 AC 73 ms
5,316 KB
testcase_30 AC 205 ms
8,864 KB
testcase_31 AC 26 ms
4,380 KB
testcase_32 AC 30 ms
4,380 KB
testcase_33 AC 219 ms
10,644 KB
testcase_34 AC 211 ms
9,388 KB
testcase_35 AC 216 ms
9,616 KB
testcase_36 AC 188 ms
9,388 KB
testcase_37 AC 217 ms
9,516 KB
testcase_38 AC 203 ms
9,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cassert>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
typedef long long ll;
using namespace std;
template <class T> void setmax(T & a, T const & b) { if (a < b) a = b; }

const ll inf = ll(1e18)+9;
int main() {
    // input
    int n, k; cin >> n >> k;
    vector<ll> t(n+1), d(n); {
        t[0] = - k;
        repeat (i,n) cin >> t[i+1] >> d[i];
    }
    // compute
    ll sum_d = whole(accumulate, d, 0ll);
    auto func = [&](ll limit) {
        vector<ll> dp(n+1, - inf); // dp
        dp[0] = 0;
        int last = 0;
        repeat (i,n) {
            int j = (whole(upper_bound, t, t[i+1]-k) - 1) - t.begin();
            assert (t[i+1] - t[j] >= k);
            if (d[i] <= limit) {
                dp[i+1] = dp[i];
                if (last <= j) setmax(dp[i+1], dp[j] + d[i]);
            } else {
                if (j < last) return inf;
                dp[i+1] = dp[j] + d[i];
                last = i+1;
            }
            assert (dp[i+1] <= inf);
        }
        return sum_d - dp[n];
    };
    vector<ll> sorted_d = d;
    sorted_d.push_back(-1);
    sorted_d.push_back(0);
    whole(sort, sorted_d);
    sorted_d.erase(whole(unique, sorted_d), sorted_d.end());
    int l = 0, r = n+1; // (l, r], binary search
    while (l+1 < r) {
        int m = (l + r) / 2;
        (func(sorted_d[m]) < inf ? r : l) = m;
    }
    // output
    ll limit = sorted_d[r];
    cout << limit << endl;
    cout << func(limit) << endl;
    return 0;
}
0