結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー monman53monman53
提出日時 2018-02-07 14:14:43
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,892 bytes
コンパイル時間 3,401 ms
コンパイル使用メモリ 167,216 KB
実行使用メモリ 39,332 KB
最終ジャッジ日時 2023-10-12 21:37:15
合計ジャッジ時間 10,808 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,352 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 304 ms
28,708 KB
testcase_18 AC 35 ms
7,204 KB
testcase_19 WA -
testcase_20 AC 120 ms
14,900 KB
testcase_21 AC 413 ms
36,056 KB
testcase_22 AC 122 ms
14,884 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 411 ms
36,016 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 42 ms
8,076 KB
testcase_32 AC 47 ms
8,776 KB
testcase_33 WA -
testcase_34 AC 454 ms
39,028 KB
testcase_35 WA -
testcase_36 AC 456 ms
39,012 KB
testcase_37 WA -
testcase_38 AC 457 ms
39,244 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), d2(n);
    map<int, vector<int>> m;
    set<int> s;
    inc(i, 0, n){
        cin >> t[i] >> d[i];
        d2[i] = d[i];
        s.insert(d[i]);
        m[d[i]].pb(i);
    }

    vector<int> v;
    for(auto ss : s) v.pb(ss);
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());

    for(auto dd : v){
        bool flag = false;
        for(auto i : m[dd]){
            if(d2[i] == 0) continue;
            inc(j, i+1, n){
                if(d2[j] == 0 || t[j]-t[i] >= k) break;
                if(d2[j] == dd) flag = true;
            }
            dec(j, 0, i){
                if(d2[j] == 0 || t[i]-t[j] >= k) break;
                if(d2[j] == dd) flag = true;
            }
        }
        if(flag) break;
        for(auto i : m[dd]){
            if(d2[i] == 0) continue;
            d[i] = d2[i] = 0;
            inc(j, i+1, n){
                if(d2[j] == 0 || t[j]-t[i] >= k) break;
                d2[j] = 0;
            }
            dec(j, 0, i){
                if(d2[j] == 0 || t[i]-t[j] >= k) break;
                d2[j] = 0;
            }
        }
    }

    BIT bit(n);
    LL mmax = 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;
            }
        }
        if(ok == n){
            mmax = max(mmax, bit.query(i)+d2[i]);
        }else{
            bit.set(ok, bit.query(i)+d2[i]);
        }
    }

    int ansmax = 0;
    LL anssum = -mmax;
    inc(i, 0, n){
        ansmax = max(ansmax, d[i]);
        anssum += d[i];
    }
    cout << ansmax << endl;
    cout << anssum << endl;

    return 0;
}
0