結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー monman53monman53
提出日時 2018-02-07 13:26:58
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,779 bytes
コンパイル時間 2,164 ms
コンパイル使用メモリ 157,960 KB
実行使用メモリ 8,540 KB
最終ジャッジ日時 2023-10-12 17:25:55
合計ジャッジ時間 7,279 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 75 ms
7,304 KB
testcase_18 AC 12 ms
4,352 KB
testcase_19 WA -
testcase_20 AC 34 ms
4,920 KB
testcase_21 AC 98 ms
8,196 KB
testcase_22 AC 36 ms
4,768 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 97 ms
8,052 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 14 ms
4,348 KB
testcase_32 AC 16 ms
4,348 KB
testcase_33 WA -
testcase_34 AC 109 ms
8,460 KB
testcase_35 WA -
testcase_36 AC 105 ms
8,536 KB
testcase_37 WA -
testcase_38 AC 108 ms
8,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(long long i=(l);i<(r);i++)
#define dec(i, l, r)   for(long long i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

struct BIT {
    vector<LL> bit;
    int n;
    BIT(int n) {
        bit.resize(n+1, 0);
        this->n = n;
    }
    LL query(int i) {
        LL mmax = 0;
        while(i > 0){
            mmax = max(mmax, bit[i]);
            // i & -i はiの最後の1のビット
            i -= i & -i;
        }
        return mmax;
    }
    void set(int i, LL x) {
        while(i <= n){
            bit[i] = max(bit[i], x);
            i += i & -i;
        }
    }
};

int main() {
    std::ios::sync_with_stdio(false);
    int n, k;cin >> n >> k;
    vector<int> t(n), d(n), v;
    priority_queue<pair<int, int>> pq;
    LL sum = 0;
    inc(i, 0, n){
        cin >> t[i] >> d[i];
        sum += d[i];
        pq.push({d[i], i});
    }
    v = d;
    int ansmax = 0;
    while(!pq.empty()){
        int i = pq.top().second;
        pq.pop();
        if(!d[i]) continue;
        bool flag = false;
        inc(j, i+1, n){
            if(d[j] == 0 || t[j]-t[i] >= k) break;
            if(d[j] == d[i]) flag = true;
        }
        dec(j, 0, i){
            if(d[j] == 0 || t[i]-t[j] >= k) break;
            if(d[j] == d[i]) flag = true;
        }
        if(flag) break;
        //cout << d[i] << endl;
        sum -= d[i];
        d[i] = 0;
        v[i] = 0;
        inc(j, i+1, n){
            if(d[j] == 0 || t[j]-t[i] >= k) break;
            //ansmax = max(ansmax, d[j]);
            d[j] = 0;
        }
        dec(j, 0, i){
            if(d[j] == 0 || t[i]-t[j] >= k) break;
            //ansmax = max(ansmax, d[j]);
            d[j] = 0;
        }
    }

    BIT bit(n);

    LL ans = 0;
    inc(i, 0, n){
        int ng = i;
        int ok = n;
        while(ok-ng>1){
            int m = (ng+ok)/2;
            if(t[m]-t[i] >= k){
                ok = m;
            }else{
                ng = m;
            }
        }
        //cout << i << " " << d[i] << " " << ok << endl;
        if(ok == n){
            ans = max(ans, bit.query(i)+d[i]);
        }else{
            bit.set(ok, bit.query(i)+d[i]);
        }
    }

    //cout << ans << endl;

    cout << *max_element(v.begin(), v.end()) << endl;
    cout << sum-ans << endl;

    return 0;
}
0