結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー latte0119latte0119
提出日時 2016-11-18 23:11:35
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 163 ms / 2,000 ms
コード長 1,850 bytes
コンパイル時間 1,478 ms
コンパイル使用メモリ 149,724 KB
実行使用メモリ 14,956 KB
最終ジャッジ日時 2023-09-02 12:50:21
合計ジャッジ時間 5,607 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 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 3 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 23 ms
4,380 KB
testcase_14 AC 26 ms
4,604 KB
testcase_15 AC 66 ms
5,572 KB
testcase_16 AC 108 ms
10,624 KB
testcase_17 AC 112 ms
7,688 KB
testcase_18 AC 19 ms
4,376 KB
testcase_19 AC 148 ms
12,772 KB
testcase_20 AC 53 ms
5,132 KB
testcase_21 AC 145 ms
8,220 KB
testcase_22 AC 55 ms
5,496 KB
testcase_23 AC 146 ms
10,300 KB
testcase_24 AC 37 ms
5,200 KB
testcase_25 AC 145 ms
9,288 KB
testcase_26 AC 18 ms
4,380 KB
testcase_27 AC 108 ms
8,512 KB
testcase_28 AC 102 ms
8,416 KB
testcase_29 AC 59 ms
6,432 KB
testcase_30 AC 153 ms
13,224 KB
testcase_31 AC 22 ms
4,376 KB
testcase_32 AC 25 ms
4,376 KB
testcase_33 AC 163 ms
14,956 KB
testcase_34 AC 157 ms
8,560 KB
testcase_35 AC 163 ms
13,392 KB
testcase_36 AC 157 ms
8,148 KB
testcase_37 AC 160 ms
11,212 KB
testcase_38 AC 157 ms
7,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int K;

bool C(int th,vpint &v){
    int pre=-1001001001;
    rep(i,v.size()){
        if(v[i].se<=th)continue;
        if(v[i].fi-pre<K)return false;
        pre=v[i].fi;
    }
    return true;
}

int dp[222222];
int solve(vpint &u){
    if(u.size()==0)return 0;
    int cur=0;
    int ma=0;
    rep(i,u.size()){
        while(cur<i&&u[i].fi-u[cur].fi>=K)chmax(ma,dp[cur++]);
        dp[i]=ma+u[i].se;
    }
    ma=*max_element(dp,dp+u.size());
    int ret=0;rep(i,u.size())ret+=u[i].se;
    return ret-ma;
}

signed main(){
    int N;
    cin>>N>>K;
    vpint v;
    rep(i,N){
        int t,d;
        cin>>t>>d;
        v.pb({t,d});
    }
    int lb=-1,ub=1001001001;
    while(ub-lb>1){
        int mid=(ub+lb)/2;
        if(C(mid,v))ub=mid;
        else lb=mid;
    }

    bool flag[222222]={};
    int pre=-1001001001;
    rep(i,N){
        if(v[i].se>ub)pre=v[i].fi;
        else{
            if(v[i].fi-pre<K)flag[i]=true;
        }
    }
    pre=INT_MAX;
    for(int i=N-1;i>=0;i--){
        if(v[i].se>ub)pre=v[i].fi;
        else{
            if(pre-v[i].fi<K)flag[i]=true;
        }
    }

    int ans=0;
    vpint u;
    rep(i,N){
        if(flag[i])ans+=v[i].se;
        else if(v[i].se<=ub)u.pb(v[i]);
    }

    ans+=solve(u);
    cout<<ub<<endl;
    cout<<ans<<endl;
    return 0;
}
0