結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー kotamanegikotamanegi
提出日時 2016-11-18 23:45:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 154 ms / 2,000 ms
コード長 1,975 bytes
コンパイル時間 918 ms
コンパイル使用メモリ 89,152 KB
実行使用メモリ 6,432 KB
最終ジャッジ日時 2023-09-02 12:51:32
合計ジャッジ時間 5,325 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 23 ms
4,380 KB
testcase_14 AC 25 ms
4,380 KB
testcase_15 AC 62 ms
4,384 KB
testcase_16 AC 102 ms
5,228 KB
testcase_17 AC 108 ms
5,368 KB
testcase_18 AC 18 ms
4,380 KB
testcase_19 AC 139 ms
6,028 KB
testcase_20 AC 50 ms
4,380 KB
testcase_21 AC 141 ms
5,840 KB
testcase_22 AC 52 ms
4,380 KB
testcase_23 AC 139 ms
5,832 KB
testcase_24 AC 35 ms
4,376 KB
testcase_25 AC 139 ms
6,004 KB
testcase_26 AC 17 ms
4,376 KB
testcase_27 AC 103 ms
5,308 KB
testcase_28 AC 96 ms
5,224 KB
testcase_29 AC 55 ms
4,416 KB
testcase_30 AC 144 ms
6,104 KB
testcase_31 AC 22 ms
4,380 KB
testcase_32 AC 24 ms
4,376 KB
testcase_33 AC 154 ms
6,280 KB
testcase_34 AC 153 ms
6,432 KB
testcase_35 AC 154 ms
6,140 KB
testcase_36 AC 150 ms
6,308 KB
testcase_37 AC 154 ms
6,268 KB
testcase_38 AC 152 ms
6,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define LONGINF 1000000000000000000
long long pass[300000] = {};
vector<pair<int, int>> listing;
int n, k;
bool can_do(long long border) {
	int ans = -1*k;
	for (int i = 0;i < n;++i) {
		if (listing[i].second >= border) {
			if (listing[i].first - ans < k) {
				return false;
			}
			else {
				ans = listing[i].first;
			}
		}
	}
	return true;
}
int main() {
	cin >> n >> k;
	REP(i, n) {
		int a, b;
		cin >> a >> b;
		listing.push_back(make_pair(a, b));
	}
	long long top = 2000000000;
	long long bot = 0;
	while (top - bot > 1) {
		long long mid = (top + bot) / 2;
		if (can_do(mid)) {
			top = mid;
		}
		else {
			bot = mid;
		}
	}
	int setting = 0;
	if (can_do(bot)) {
		setting = bot;
	}
	else {
		setting = top;
	}
	listing.insert(listing.begin(), make_pair(-1 * k, 0));
	int now_reading = 0;
	for (int i = 1;i < n+1;++i) {
		while (now_reading + 1 != i) {
			if (listing[i].first - listing[now_reading + 1].first < k) break;
			now_reading++;
		}
		if (listing[i].first - listing[now_reading].first >= k) {
			pass[i] = max(pass[now_reading] + listing[i].second, pass[i - 1]);
			if (listing[i].second >= setting) {
				now_reading = i;
			}
		}
		else {
			pass[i] = pass[i - 1];
		}
	}
	long long max_ans = 0;
	long long ans = 0;
	for (int i = 0;i < n + 1;++i) {
		ans += listing[i].second;
		if(listing[i].second < setting)
		max_ans = max(max_ans,(long long)listing[i].second);
	}
	cout << max_ans << endl;
	cout << ans - pass[n] << endl;
	return 0;
}
0