結果

問題 No.1715 Dinner 2
ユーザー nok0nok0
提出日時 2021-10-08 11:13:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 137 ms / 2,000 ms
コード長 1,000 bytes
コンパイル時間 2,097 ms
コンパイル使用メモリ 207,484 KB
実行使用メモリ 7,248 KB
最終ジャッジ日時 2023-10-24 11:32:07
合計ジャッジ時間 6,054 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 105 ms
6,456 KB
testcase_12 AC 85 ms
5,928 KB
testcase_13 AC 72 ms
5,400 KB
testcase_14 AC 85 ms
5,928 KB
testcase_15 AC 88 ms
5,928 KB
testcase_16 AC 82 ms
5,664 KB
testcase_17 AC 51 ms
4,872 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 5 ms
4,348 KB
testcase_20 AC 4 ms
4,348 KB
testcase_21 AC 4 ms
4,348 KB
testcase_22 AC 3 ms
4,348 KB
testcase_23 AC 5 ms
4,348 KB
testcase_24 AC 4 ms
4,348 KB
testcase_25 AC 12 ms
4,348 KB
testcase_26 AC 9 ms
4,348 KB
testcase_27 AC 9 ms
4,348 KB
testcase_28 AC 11 ms
4,348 KB
testcase_29 AC 11 ms
4,348 KB
testcase_30 AC 11 ms
4,348 KB
testcase_31 AC 11 ms
4,348 KB
testcase_32 AC 133 ms
7,248 KB
testcase_33 AC 132 ms
7,248 KB
testcase_34 AC 134 ms
7,248 KB
testcase_35 AC 137 ms
7,248 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 5 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define rep(i, x) for(int i = 0; i < (x); i++)

const int inf = 1 << 29;

int main() {
	int n, d;
	cin >> n >> d;
	vector<int> p(n), q(n);
	rep(i, n) { cin >> p[i] >> q[i]; }

	auto f = [&](int x) {
		vector dp(d + 1, vector(n, -inf));
		rep(i, n) {
			if(-p[i] < x) continue;
			dp[1][i] = q[i] - p[i];
		}
		for(int i = 1; i < d; i++) {
			auto vec = dp[i];
			auto mx = -inf, mx2 = -inf;
			rep(j, n) {
				if(mx < dp[i][j]) {
					mx2 = mx, mx = dp[i][j];
				} else if(mx2 < dp[i][j]) {
					mx2 = dp[i][j];
				}
			}
			rep(j, n) {
				if(dp[i][j] != mx) {
					if(mx - p[j] < x) continue;
					dp[i + 1][j] = mx - p[j] + q[j];
				} else {
					if(mx2 - p[j] < x) continue;
					dp[i + 1][j] = mx2 - p[j] + q[j];
				}
			}
		}
		return *max_element(dp.back().begin(), dp.back().end()) > -inf;
	};

	int ok = -inf, ng = inf;
	while(abs(ok - ng) > 1) {
		int mid = (ok + ng) / 2;
		(f(mid) ? ok : ng) = mid;
	}
	cout << ok << endl;
	
	return 0;
}
0