結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー azbrugbyazbrugby
提出日時 2019-03-03 17:33:48
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 157 ms / 2,000 ms
コード長 2,062 bytes
コンパイル時間 653 ms
コンパイル使用メモリ 78,768 KB
実行使用メモリ 9,752 KB
最終ジャッジ日時 2023-09-05 17:47:19
合計ジャッジ時間 5,171 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,528 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 3 ms
6,776 KB
testcase_03 AC 3 ms
6,580 KB
testcase_04 AC 3 ms
6,484 KB
testcase_05 AC 3 ms
6,476 KB
testcase_06 AC 4 ms
6,536 KB
testcase_07 AC 3 ms
6,484 KB
testcase_08 AC 3 ms
6,524 KB
testcase_09 AC 4 ms
6,496 KB
testcase_10 AC 4 ms
6,524 KB
testcase_11 AC 3 ms
6,476 KB
testcase_12 AC 3 ms
6,488 KB
testcase_13 AC 23 ms
6,916 KB
testcase_14 AC 27 ms
6,968 KB
testcase_15 AC 65 ms
7,700 KB
testcase_16 AC 105 ms
8,616 KB
testcase_17 AC 111 ms
8,832 KB
testcase_18 AC 20 ms
6,832 KB
testcase_19 AC 144 ms
9,324 KB
testcase_20 AC 52 ms
7,492 KB
testcase_21 AC 142 ms
9,332 KB
testcase_22 AC 54 ms
7,532 KB
testcase_23 AC 143 ms
9,336 KB
testcase_24 AC 37 ms
7,312 KB
testcase_25 AC 143 ms
9,356 KB
testcase_26 AC 19 ms
6,856 KB
testcase_27 AC 105 ms
8,580 KB
testcase_28 AC 99 ms
8,716 KB
testcase_29 AC 57 ms
7,560 KB
testcase_30 AC 147 ms
9,456 KB
testcase_31 AC 23 ms
6,896 KB
testcase_32 AC 26 ms
7,016 KB
testcase_33 AC 157 ms
9,596 KB
testcase_34 AC 155 ms
9,600 KB
testcase_35 AC 157 ms
9,648 KB
testcase_36 AC 157 ms
9,752 KB
testcase_37 AC 157 ms
9,604 KB
testcase_38 AC 156 ms
9,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <stack>
#include <cstdio>
#include <cmath>
#define mk make_pair
#define pb push_back
#define printf printf_s
#define scanf scanf_s
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pos;
const ll MOD = 1000000007, N = 200001, dx[4] = { -1,1,0,0 }, dy[4] = { 0,0,-1,1 }, MIN = -72340172838, MAX = 72340172838;

ll mn(ll a, ll b) {
	if (a == -1)return b;
	if (b == -1)return a;
	return min(a, b);
}
ll gcd(ll v1, ll v2) {
	if (v1 == 0)return v2; if (v2 == 0)return v1; if (v2 > v1)return gcd(v2%v1, v1); return gcd(v1%v2, v2);
}

ll pw(ll v1, ll v2) {
	ll v3 = 1;
	while (v2 > 0) {
		if (v2 % 2)v3 = (v3*v1) % MOD;
		v1 = (v1*v1) % MOD;
		v2 /= 2;
	}
	return v3;
}

struct ab {
	ll a, b;
	bool operator<(const ab& right) const {
		return right.b*a - right.a*b < 0;
	}
};

ll n, k, mx, mnv, ans = 0;
pos pr[N];
queue<ll> ql;

bool ok(ll md) {
	ll bt = MIN;
	for (int i = 0; i < n; i++) {
		if (pr[i].second <= md)continue;
		if (pr[i].first - bt < k)return false;
		bt = pr[i].first;
	}
	return true;
}

int main() {
	cin >> n >> k;
	for (int i = 0; i < n; i++) { cin >> pr[i].first >> pr[i].second; mx = max(mx, pr[i].second); ans += pr[i].second; }
	if (ok(0)) { cout << 0 << endl << 0 << endl; return 0; }
	while (mx - mnv > 1) {
		ll md = (mx + mnv) / 2;
		if (ok(md))mx = md;
		else mnv = md;
	}
	cout << mx << endl;

	for (int i = 0; i < n; i++) { if (pr[i].second > mx) { ql.push(pr[i].first); ans -= pr[i].second; } }
	ql.push(MAX);

	ll dp[N] = {}, mxv[N] = {},lt=MIN,bt=-1;
	for (int i = 0; i < n; i++) {
		while (ql.front() < pr[i].first) { lt = ql.front(); ql.pop(); }
		if (pr[i].first - lt >= k && ql.front() -pr[i].first >= k) {
			while (pr[i].first - pr[bt + 1].first>=k)bt++;
			ll btv = 0;
			if (bt != -1)btv = mxv[bt];
			dp[i] = btv + pr[i].second;
		}
		if (i != 0)mxv[i] = max(dp[i], mxv[i - 1]);
		else mxv[i] = dp[i];
	}
	cout << ans - mxv[n - 1] << endl;
	return 0;
}
0