結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー startcppstartcpp
提出日時 2016-11-19 00:01:27
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 164 ms / 2,000 ms
コード長 1,758 bytes
コンパイル時間 599 ms
コンパイル使用メモリ 58,792 KB
実行使用メモリ 10,016 KB
最終ジャッジ日時 2023-09-02 12:52:34
合計ジャッジ時間 5,139 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,592 KB
testcase_01 AC 3 ms
7,460 KB
testcase_02 AC 2 ms
7,752 KB
testcase_03 AC 2 ms
7,532 KB
testcase_04 AC 2 ms
7,464 KB
testcase_05 AC 2 ms
7,464 KB
testcase_06 AC 2 ms
7,468 KB
testcase_07 AC 3 ms
7,628 KB
testcase_08 AC 3 ms
7,468 KB
testcase_09 AC 2 ms
7,468 KB
testcase_10 AC 3 ms
7,468 KB
testcase_11 AC 3 ms
7,460 KB
testcase_12 AC 3 ms
7,616 KB
testcase_13 AC 24 ms
7,888 KB
testcase_14 AC 27 ms
8,072 KB
testcase_15 AC 66 ms
8,836 KB
testcase_16 AC 109 ms
9,000 KB
testcase_17 AC 114 ms
9,216 KB
testcase_18 AC 20 ms
7,812 KB
testcase_19 AC 149 ms
9,512 KB
testcase_20 AC 54 ms
8,484 KB
testcase_21 AC 148 ms
9,696 KB
testcase_22 AC 56 ms
8,464 KB
testcase_23 AC 149 ms
9,620 KB
testcase_24 AC 37 ms
8,144 KB
testcase_25 AC 148 ms
9,516 KB
testcase_26 AC 19 ms
7,860 KB
testcase_27 AC 111 ms
8,980 KB
testcase_28 AC 104 ms
8,992 KB
testcase_29 AC 59 ms
8,484 KB
testcase_30 AC 153 ms
9,620 KB
testcase_31 AC 24 ms
7,916 KB
testcase_32 AC 26 ms
8,024 KB
testcase_33 AC 164 ms
9,872 KB
testcase_34 AC 162 ms
9,788 KB
testcase_35 AC 163 ms
10,016 KB
testcase_36 AC 159 ms
9,864 KB
testcase_37 AC 163 ms
9,936 KB
testcase_38 AC 162 ms
9,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//難しさの最大値=Tなら、T+1以上のタスクをYukiさんに頼んでそれ以外を自分でやると「Yukiさんの体にやさしい」
//それで無理なら答えはTを超える, OKなら答えはT以下。(st, ed]で2分探索できる.
//難しさ(答え)を求めたら, 総和はちょっと工夫したDPで求まる。(こっちが本質!!)

#include <iostream>
#include <algorithm>
#define int long long
using namespace std;

int n, k;
int t[200000], d[200000];
bool mustWork[200000];
int mustWorkR[200001];
int dp[200001];		//dp[i] = 時刻t[i]からYukiさんを起こせる場合の, それまでにYukiさんがした仕事の量の最大

bool check(int mid) {
	int i;
	int now = -1145141919;
	
	for (i = 0; i < n; i++) {
		if (d[i] > mid) {
			if (now + k > t[i]) return false;
			now = t[i];
		}
	}
	return true;
}

signed main() {
	int i;
	
	cin >> n >> k;
	for (i = 0; i < n; i++) { cin >> t[i] >> d[i]; }
	
	int st = -1, ed = 1000000000, mid;	//(st, ed]
	while (ed - st >= 2) {
		mid = (st + ed) / 2;
		if (check(mid)) { ed = mid; }
		else { st = mid; }
	}
	
	cout << ed << endl;
	
	for (i = 0; i < n; i++) { mustWork[i] = (ed < d[i]); }
	for (i = 1; i <= n; i++) { mustWorkR[i] = mustWork[i-1] + mustWorkR[i-1]; }
	
	for (i = 0; i <= n; i++) { dp[i] = -1145141919893810; }
	dp[0] = 0;
	
	for (i = 0; i < n; i++) {
		int id = lower_bound(t, t + n, t[i] + k) - t;
		
		//もし, mustWork[i+1]~mustWork[id-1]内にtrueがあったら働いちゃだめ
		if (mustWorkR[id] - mustWorkR[i+1] == 0) {
			dp[id] = max(dp[id], dp[i] + d[i]);
		}
		
		if (!mustWork[i]) { dp[i + 1] = max(dp[i + 1], dp[i]); }
	}
	
	int ans = 0;
	for (i = 0; i < n; i++) { ans += d[i]; }
	ans -= dp[n];
	cout << ans << endl;
	return 0;
}
0