結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー monman53monman53
提出日時 2018-02-07 15:32:15
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 450 ms / 2,000 ms
コード長 2,912 bytes
コンパイル時間 1,982 ms
コンパイル使用メモリ 167,464 KB
実行使用メモリ 39,096 KB
最終ジャッジ日時 2023-10-13 10:32:42
合計ジャッジ時間 12,186 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,368 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 39 ms
8,012 KB
testcase_14 AC 47 ms
8,748 KB
testcase_15 AC 150 ms
17,604 KB
testcase_16 AC 278 ms
26,704 KB
testcase_17 AC 300 ms
28,860 KB
testcase_18 AC 32 ms
7,480 KB
testcase_19 AC 402 ms
35,760 KB
testcase_20 AC 118 ms
14,892 KB
testcase_21 AC 401 ms
36,160 KB
testcase_22 AC 119 ms
15,076 KB
testcase_23 AC 415 ms
36,212 KB
testcase_24 AC 72 ms
10,988 KB
testcase_25 AC 391 ms
35,832 KB
testcase_26 AC 29 ms
6,968 KB
testcase_27 AC 280 ms
27,472 KB
testcase_28 AC 253 ms
25,588 KB
testcase_29 AC 126 ms
15,828 KB
testcase_30 AC 418 ms
37,060 KB
testcase_31 AC 41 ms
8,056 KB
testcase_32 AC 47 ms
8,716 KB
testcase_33 AC 442 ms
38,996 KB
testcase_34 AC 440 ms
38,952 KB
testcase_35 AC 448 ms
38,928 KB
testcase_36 AC 445 ms
39,048 KB
testcase_37 AC 450 ms
39,096 KB
testcase_38 AC 449 ms
38,944 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){
                flag = true;
                break;
            }
            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]){
            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