結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー mamekinmamekin
提出日時 2016-11-19 17:11:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 159 ms / 2,000 ms
コード長 1,962 bytes
コンパイル時間 836 ms
コンパイル使用メモリ 105,648 KB
実行使用メモリ 7,252 KB
最終ジャッジ日時 2023-09-02 12:55:37
合計ジャッジ時間 5,065 ms
ジャッジサーバーID
(参考情報)
judge16 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 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 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 22 ms
4,376 KB
testcase_14 AC 24 ms
4,380 KB
testcase_15 AC 60 ms
4,704 KB
testcase_16 AC 102 ms
5,624 KB
testcase_17 AC 110 ms
5,620 KB
testcase_18 AC 19 ms
4,376 KB
testcase_19 AC 140 ms
6,420 KB
testcase_20 AC 49 ms
4,384 KB
testcase_21 AC 140 ms
6,540 KB
testcase_22 AC 52 ms
4,380 KB
testcase_23 AC 139 ms
6,872 KB
testcase_24 AC 33 ms
4,380 KB
testcase_25 AC 141 ms
6,492 KB
testcase_26 AC 17 ms
4,380 KB
testcase_27 AC 103 ms
5,700 KB
testcase_28 AC 93 ms
5,356 KB
testcase_29 AC 55 ms
4,476 KB
testcase_30 AC 142 ms
6,740 KB
testcase_31 AC 22 ms
4,376 KB
testcase_32 AC 24 ms
4,376 KB
testcase_33 AC 155 ms
7,092 KB
testcase_34 AC 152 ms
7,092 KB
testcase_35 AC 156 ms
7,024 KB
testcase_36 AC 159 ms
7,252 KB
testcase_37 AC 151 ms
7,100 KB
testcase_38 AC 152 ms
7,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

const int MAX = 1000000000;
const long long INF = LLONG_MAX / 4;

int solve1(const vector<int>& t, const vector<long long>& d, int k)
{
    int n = t.size();
    int left = 0;
    int right = MAX;
    while(left < right){
        int mid = (left + right) / 2;
        int prev = -MAX;
        bool ok = true;
        for(int i=0; i<n; ++i){
            if(d[i] > mid){
                if(t[i] - prev < k)
                    ok = false;
                prev = t[i];
            }
        }
        if(ok)
            right = mid;
        else
            left = mid + 1;
    }
    return left;
}

long long solve2(const vector<int>& t, const vector<long long>& d, int k, int x)
{
    int n = t.size();
    int i = 0;
    int j = 0;
    long long maxVal = 0;
    vector<long long> dp(n+1, -INF);
    dp[0] = 0;

    for(int i=0; i<n; ++i){
        while(t[j] + k <= t[i]){
            ++ j;
            maxVal = max(maxVal, dp[j]);
        }
        if(d[i] <= x){
            if(j == 0 || t[j-1] + k <= t[i])
                dp[i+1] = maxVal + d[i];
        }
        else{
            dp[i+1] = maxVal + d[i];
            j = i;
            maxVal = -INF;
        }
    }
    return accumulate(d.begin(), d.end(), 0LL) - *max_element(dp.begin(), dp.end());
}

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> t(n);
    vector<long long> d(n);
    for(int i=0; i<n; ++i)
        cin >> t[i] >> d[i];

    int x = solve1(t, d, k);
    cout << x << endl << solve2(t, d, k, x) << endl;

    return 0;
}
0