結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー milanis48663220milanis48663220
提出日時 2020-07-08 23:46:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 1,501 bytes
コンパイル時間 776 ms
コンパイル使用メモリ 89,388 KB
実行使用メモリ 8,124 KB
最終ジャッジ日時 2023-07-27 23:44:29
合計ジャッジ時間 5,801 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,488 KB
testcase_01 AC 2 ms
5,420 KB
testcase_02 AC 2 ms
5,460 KB
testcase_03 AC 2 ms
5,476 KB
testcase_04 AC 2 ms
5,600 KB
testcase_05 AC 2 ms
5,688 KB
testcase_06 AC 2 ms
5,444 KB
testcase_07 AC 2 ms
5,732 KB
testcase_08 AC 2 ms
5,424 KB
testcase_09 AC 2 ms
5,488 KB
testcase_10 AC 2 ms
5,500 KB
testcase_11 AC 2 ms
5,444 KB
testcase_12 AC 2 ms
5,436 KB
testcase_13 AC 10 ms
6,004 KB
testcase_14 AC 11 ms
5,944 KB
testcase_15 AC 25 ms
6,628 KB
testcase_16 AC 42 ms
7,192 KB
testcase_17 AC 43 ms
7,160 KB
testcase_18 AC 8 ms
5,764 KB
testcase_19 AC 58 ms
7,808 KB
testcase_20 AC 22 ms
6,532 KB
testcase_21 AC 57 ms
7,796 KB
testcase_22 AC 22 ms
6,520 KB
testcase_23 AC 59 ms
7,856 KB
testcase_24 AC 16 ms
6,164 KB
testcase_25 AC 58 ms
7,884 KB
testcase_26 AC 8 ms
5,808 KB
testcase_27 AC 43 ms
7,044 KB
testcase_28 AC 40 ms
6,948 KB
testcase_29 AC 24 ms
6,452 KB
testcase_30 AC 60 ms
7,876 KB
testcase_31 AC 10 ms
5,904 KB
testcase_32 AC 11 ms
6,168 KB
testcase_33 AC 64 ms
8,052 KB
testcase_34 AC 63 ms
8,052 KB
testcase_35 AC 63 ms
8,124 KB
testcase_36 AC 60 ms
8,060 KB
testcase_37 AC 64 ms
8,056 KB
testcase_38 AC 63 ms
8,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int N, K;
ll T[200002];
ll D[200002];
ll dp[200002];

bool ok(ll d){
    ll pre = T[0];
    for(int i = 1; i <= N; i++){
        if(D[i] > d) {
            if(T[i]-pre < K) return false;
            else pre = T[i];
        }
    }
    return true;
}

set<ll> st;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> K;
    ll sum = 0;
    for(int i = 1; i <= N; i++) {
        cin >> T[i] >> D[i];
        sum += D[i];
    }
    T[0] = -1e12, T[N+1] = 1e12;
    if(ok(0)){
        cout << 0 << endl;
        cout << 0 << endl;
        return 0;
    }
    st.insert(-1e12); st.insert(1e12);
    ll l = 0, r = 1e9;
    while(r-l > 1){
        ll c = (l+r)/2;
        if(ok(c)) r = c;
        else l = c;
    }
    ll d = r;
    for(int i = 1; i <= N; i++){
        if(D[i] > d) st.insert(T[i]);
    }
    for(int i = 1; i <= N; i++){
        auto p = upper_bound(T, T+N+2, T[i]-K); p--;
        int dif = p-T;
        if(D[i] > d){
            dp[i] = dp[dif]+D[i];
        }else{
            auto ptl = st.lower_bound(T[i]); ptl--;
            auto ptr = st.upper_bound(T[i]);
            if(T[i]-(*ptl) < K || *ptr-T[i] < K) dp[i] = dp[i-1];
            else dp[i] = max(dp[i-1], dp[dif]+D[i]);
        }
    }
    cout << d << endl;
    cout << sum-dp[N] << endl;
}
0