結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー kimiyukikimiyuki
提出日時 2016-11-19 00:18:04
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 253 ms / 2,000 ms
コード長 3,145 bytes
コンパイル時間 1,073 ms
コンパイル使用メモリ 101,704 KB
実行使用メモリ 10,244 KB
最終ジャッジ日時 2023-09-02 12:53:04
合計ジャッジ時間 6,505 ms
ジャッジサーバーID
(参考情報)
judge15 / 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,380 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,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 32 ms
4,376 KB
testcase_14 AC 31 ms
4,376 KB
testcase_15 AC 84 ms
5,616 KB
testcase_16 AC 157 ms
7,024 KB
testcase_17 AC 137 ms
7,836 KB
testcase_18 AC 23 ms
4,376 KB
testcase_19 AC 202 ms
8,656 KB
testcase_20 AC 69 ms
5,156 KB
testcase_21 AC 196 ms
8,804 KB
testcase_22 AC 74 ms
5,164 KB
testcase_23 AC 201 ms
8,988 KB
testcase_24 AC 48 ms
4,448 KB
testcase_25 AC 207 ms
9,128 KB
testcase_26 AC 23 ms
4,376 KB
testcase_27 AC 148 ms
7,500 KB
testcase_28 AC 143 ms
6,956 KB
testcase_29 AC 74 ms
5,448 KB
testcase_30 AC 212 ms
9,008 KB
testcase_31 AC 26 ms
4,380 KB
testcase_32 AC 28 ms
4,376 KB
testcase_33 AC 253 ms
9,996 KB
testcase_34 AC 212 ms
9,444 KB
testcase_35 AC 218 ms
9,512 KB
testcase_36 AC 186 ms
9,384 KB
testcase_37 AC 218 ms
10,244 KB
testcase_38 AC 204 ms
9,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <set>
#include <map>
#include <queue>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <cmath>
#include <cassert>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i,m,n) for (int i = (m); (i) < (n); ++(i))
#define repeat_reverse(i,n) for (int i = (n)-1; (i) >= 0; --(i))
#define repeat_from_reverse(i,m,n) for (int i = (n)-1; (i) >= (m); --(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; }
template <class T> void setmin(T & a, T const & b) { if (b < a) a = b; }

template <typename T>
struct segment_tree { // on monoid
    int n;
    vector<T> a;
    function<T (T,T)> append; // associative
    T unit; // unit
    segment_tree() = default;
    template <typename F>
    segment_tree(int a_n, T a_unit, F a_append) {
        n = pow(2,ceil(log2(a_n)));
        a.resize(2*n-1, a_unit);
        unit = a_unit;
        append = a_append;
    }
    void point_update(int i, T z) {
        a[i+n-1] = z;
        for (i = (i+n)/2; i > 0; i /= 2) {
            a[i-1] = append(a[2*i-1], a[2*i]);
        }
    }
    T range_concat(int l, int r) {
        return range_concat(0, 0, n, l, r);
    }
    T range_concat(int i, int il, int ir, int l, int r) {
        if (l <= il and ir <= r) {
            return a[i];
        } else if (ir <= l or r <= il) {
            return unit;
        } else {
            return append(
                    range_concat(2*i+1, il, (il+ir)/2, l, r),
                    range_concat(2*i+2, (il+ir)/2, ir, l, r));
        }
    }
};
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);
    sorted_d.push_back(inf);
    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