結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー firiexpfiriexp
提出日時 2019-12-27 11:53:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 1,681 bytes
コンパイル時間 1,144 ms
コンパイル使用メモリ 103,988 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-04-27 15:47:14
合計ジャッジ時間 5,335 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 10 ms
5,376 KB
testcase_14 AC 13 ms
5,376 KB
testcase_15 AC 25 ms
5,376 KB
testcase_16 AC 50 ms
6,528 KB
testcase_17 AC 36 ms
5,376 KB
testcase_18 AC 7 ms
5,376 KB
testcase_19 AC 74 ms
10,368 KB
testcase_20 AC 22 ms
5,376 KB
testcase_21 AC 66 ms
8,448 KB
testcase_22 AC 25 ms
5,632 KB
testcase_23 AC 68 ms
9,216 KB
testcase_24 AC 18 ms
5,376 KB
testcase_25 AC 60 ms
8,960 KB
testcase_26 AC 9 ms
5,376 KB
testcase_27 AC 44 ms
6,272 KB
testcase_28 AC 56 ms
9,728 KB
testcase_29 AC 25 ms
5,760 KB
testcase_30 AC 68 ms
8,576 KB
testcase_31 AC 9 ms
5,376 KB
testcase_32 AC 9 ms
5,376 KB
testcase_33 AC 75 ms
8,448 KB
testcase_34 AC 54 ms
7,680 KB
testcase_35 AC 82 ms
10,624 KB
testcase_36 AC 52 ms
6,528 KB
testcase_37 AC 77 ms
9,344 KB
testcase_38 AC 50 ms
6,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <limits>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> ts(n), ds(n);
    for (int i = 0; i < n; ++i) {
        scanf("%d %d", &ts[i], &ds[i]);
    }
    int ng = -1, ok = 1000000000;
    while(ok-ng > 1){
        int mid = (ok+ng)/2;
        int prv = -INF<int>, good = 1;
        for (int i = 0; i < n; ++i) {
            if(mid < ds[i]){
                if(ts[i]-prv < k){
                    good = 0;
                    break;
                }else prv = ts[i];
            }
        }
        (good ? ok : ng) = mid;
    }
    ll ans = accumulate(ds.begin(),ds.end(), 0LL);
    vector<ll> dp(n+1, -INF<ll>); // iで最後に任せたときの任せる仕事の量の最大値
    int cur = 0;
    dp[0] = 0;
    set<ll, greater<>> S;
    S.emplace(0);
    for (int i = 0; i < n; ++i) {
        while(cur < n && ts[cur] + k <= ts[i]){
            if(dp[cur+1] != 0) S.emplace(dp[cur+1]);
            cur++;
        }
        if(ds[i] > ok){ // 必ず任せる
            dp[i+1] = *S.begin() + ds[i];
            cur = i;
            S.clear();
        }else {
            if(!S.empty()){
                dp[i+1] = *S.begin() + ds[i];
            }
        }
    }
    cout << ok << "\n";
    cout << ans-*max_element(dp.begin(),dp.end()) << "\n";
    return 0;
}
0