結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー ctyl_0ctyl_0
提出日時 2016-11-24 16:50:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,815 bytes
コンパイル時間 966 ms
コンパイル使用メモリ 103,168 KB
実行使用メモリ 10,912 KB
最終ジャッジ日時 2024-05-05 12:56:08
合計ジャッジ時間 4,690 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 41 ms
6,676 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 10 ms
5,376 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます

ソースコード

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;
        
    }
    sum += dp[B.size() - 1];
    
    output(sum_all - sum);
    
    return 0;
}
0