結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー imulanimulan
提出日時 2016-11-19 03:15:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 1,856 bytes
コンパイル時間 1,452 ms
コンパイル使用メモリ 170,100 KB
実行使用メモリ 7,804 KB
最終ジャッジ日時 2023-09-02 12:55:20
合計ジャッジ時間 4,288 ms
ジャッジサーバーID
(参考情報)
judge16 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 9 ms
4,380 KB
testcase_14 AC 10 ms
4,380 KB
testcase_15 AC 22 ms
4,380 KB
testcase_16 AC 36 ms
6,024 KB
testcase_17 AC 35 ms
4,380 KB
testcase_18 AC 7 ms
4,380 KB
testcase_19 AC 50 ms
6,824 KB
testcase_20 AC 18 ms
4,380 KB
testcase_21 AC 47 ms
5,372 KB
testcase_22 AC 19 ms
4,376 KB
testcase_23 AC 49 ms
5,800 KB
testcase_24 AC 13 ms
4,380 KB
testcase_25 AC 48 ms
5,488 KB
testcase_26 AC 7 ms
4,376 KB
testcase_27 AC 35 ms
5,216 KB
testcase_28 AC 35 ms
5,676 KB
testcase_29 AC 20 ms
4,532 KB
testcase_30 AC 51 ms
6,972 KB
testcase_31 AC 8 ms
4,380 KB
testcase_32 AC 9 ms
4,380 KB
testcase_33 AC 55 ms
6,976 KB
testcase_34 AC 52 ms
5,292 KB
testcase_35 AC 58 ms
7,804 KB
testcase_36 AC 52 ms
5,452 KB
testcase_37 AC 55 ms
6,392 KB
testcase_38 AC 50 ms
4,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

ll dp[200001]={0};

int main()
{
    int n,k;
    scanf(" %d %d", &n, &k);
    vector<int> t(n), d(n);
    int D=0;
    rep(i,n)
    {
        scanf(" %d %d", &t[i], &d[i]);
        D=max(D,d[i]);
    }

    int l=-1, r=D;
    while(r-l>1)
    {
        int m=(l+r)/2;

        bool ok=true;
        int b=-k;
        rep(i,n)
        {
            if(d[i]>m)
            {
                if(t[i]-b<k)
                {
                    ok=false;
                    break;
                }
                b=t[i];
            }
        }

        if(ok) r=m;
        else l=m;
    }

    vector<bool> yuki(n,true);
    int b=-k;
    rep(i,n)
    {
        if(d[i]>r)
        {
            b=t[i];
            yuki[i]=false;
        }
        else
        {
            if(t[i]-b<k) yuki[i]=false;
        }
    }
    b=2000000001;
    for(int i=n-1; i>=0; --i)
    {
        if(d[i]>r)
        {
            b=t[i];
            yuki[i]=false;
        }
        else
        {
            if(b-t[i]<k) yuki[i]=false;
        }
    }

    vector<int> yt,yd;
    rep(i,n)
    {
        if(yuki[i])
        {
            yt.pb(t[i]);
            yd.pb(d[i]);
        }
    }

    int Y=yt.size();
    int lidx=0;
    rep(i,Y)
    {
        while(i>lidx)
        {
            if(yt[i]-yt[lidx]<k) break;
            ++lidx;
        }
        dp[i+1] = max(dp[i],dp[lidx]+yd[i]);
    }

    ll sum=0;
    ll yuki_sum=dp[Y];
    rep(i,n)
    {
        sum+=d[i];
        if(d[i]>r) yuki_sum+=d[i];
    }

    printf("%d\n%lld\n",r,sum-yuki_sum);
    return 0;
}
0