結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー ctyl_0ctyl_0
提出日時 2016-11-24 16:55:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 410 ms / 2,000 ms
コード長 2,860 bytes
コンパイル時間 1,148 ms
コンパイル使用メモリ 102,504 KB
実行使用メモリ 11,740 KB
最終ジャッジ日時 2023-09-02 12:58:41
合計ジャッジ時間 5,297 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 13 ms
4,376 KB
testcase_14 AC 30 ms
4,380 KB
testcase_15 AC 106 ms
5,344 KB
testcase_16 AC 56 ms
8,412 KB
testcase_17 AC 43 ms
6,296 KB
testcase_18 AC 9 ms
4,376 KB
testcase_19 AC 200 ms
11,676 KB
testcase_20 AC 26 ms
4,852 KB
testcase_21 AC 56 ms
7,752 KB
testcase_22 AC 75 ms
5,028 KB
testcase_23 AC 248 ms
9,224 KB
testcase_24 AC 29 ms
4,520 KB
testcase_25 AC 189 ms
7,808 KB
testcase_26 AC 12 ms
4,380 KB
testcase_27 AC 83 ms
7,028 KB
testcase_28 AC 124 ms
7,316 KB
testcase_29 AC 51 ms
5,992 KB
testcase_30 AC 162 ms
10,980 KB
testcase_31 AC 10 ms
4,376 KB
testcase_32 AC 11 ms
4,380 KB
testcase_33 AC 122 ms
11,740 KB
testcase_34 AC 60 ms
7,212 KB
testcase_35 AC 85 ms
10,964 KB
testcase_36 AC 59 ms
7,764 KB
testcase_37 AC 410 ms
9,428 KB
testcase_38 AC 60 ms
7,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template
ll K;
vector<pair<ll, ll>> A;

bool ok(ll N){
    vector<ll> T;
    rep(i, A.size()){
        if(A[i].second >= N){
            T.pb(A[i].first);
        }
    }
    
    ll cur = -inf;
    rep(i, T.size()){
        if(T[i] - cur >= K){
            cur = T[i];
        }
        else return false;
    }
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    
    cin >> N >> K;
    A.resize(N);
    ll r = 0;
    ll sum_all = 0;
    rep(i, N) cin >> A[i].first >> A[i].second, r = max(r, A[i].second), sum_all += A[i].second;
    ll l = -1;
    while(l + 1 < r){
        ll mid = (l + r) / 2;
        if(ok(mid)){
            r = mid;
        }
        else l = mid;
    }
    //    rep(i, 4, 8){
    //        cout << i << ":" << ok(i) << endl;
    //    }
    
    int ind = 0;
    ll ind_max = 0;
    
    ll sum = 0;
    ll ret = 0;
    
    vector<ll> T; // r以上の時刻 (T, T + 2K)の間はyukiさんは仕事ができない
    rep(i, A.size()){
        if(A[i].second >= r){
            T.pb(A[i].first - K);
            sum += A[i].second;
        }
        else{
            ret = max(ret, A[i].second);
        }
    }
    
    output(ret);
    
    vector<pair<ll, ll>> B; // コストr未満でyukiさんが仕事ができる可能性のあるセル
    B.pb(mp(-inf, 0));
    int cur = 0;
    if(T.size()){
        rep(i, A.size()){
            while(T[cur] + 2 * K < A[i].first && cur < T.size() - 1) cur++;
            if(A[i].second <= ret && (A[i].first <= T[cur] || T[cur] + 2 * K <= A[i].first)) B.pb(A[i]);
        }
    }
    
    
    
    vector<ll> dp(B.size());
    
    rep(i, B.size()){
        
        int ind_tmp = ind;
        while(B[i].first - B[ind_tmp].first >= K){
            if(dp[ind_tmp] > ind_max){
                ind_max = dp[ind_tmp];
                ind = ind_tmp;
            }
            ind_tmp++;
        }
        dp[i] = dp[ind] + B[i].second;
        
    }
    
    ll m = 0;
    rep(i, dp.size()) m = max(m, dp[i]);
    sum += m;
    
    output(sum_all - sum);
    
    return 0;
}
0