結果

問題 No.1715 Dinner 2
ユーザー nok0nok0
提出日時 2021-10-23 12:53:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 831 bytes
コンパイル時間 2,266 ms
コンパイル使用メモリ 207,604 KB
実行使用メモリ 7,284 KB
最終ジャッジ日時 2023-10-25 08:45:30
合計ジャッジ時間 4,614 ms
ジャッジサーバーID
(参考情報)
judge15 / 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 108 ms
6,492 KB
testcase_12 AC 87 ms
5,964 KB
testcase_13 AC 73 ms
5,436 KB
testcase_14 AC 87 ms
5,964 KB
testcase_15 AC 88 ms
5,964 KB
testcase_16 AC 84 ms
5,700 KB
testcase_17 AC 52 ms
4,908 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 4 ms
4,348 KB
testcase_20 AC 3 ms
4,348 KB
testcase_21 AC 3 ms
4,348 KB
testcase_22 AC 3 ms
4,348 KB
testcase_23 AC 4 ms
4,348 KB
testcase_24 AC 3 ms
4,348 KB
testcase_25 AC 12 ms
4,348 KB
testcase_26 AC 8 ms
4,348 KB
testcase_27 AC 8 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 140 ms
7,284 KB
testcase_33 AC 141 ms
7,284 KB
testcase_34 AC 140 ms
7,284 KB
testcase_35 AC 142 ms
7,284 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 4 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));
		dp[0].assign(n, 0);
		rep(i, d) {
			int 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) {
				const int tmp = (dp[i][j] != mx ? mx : mx2);
				if(tmp - p[j] < x) continue;
				dp[i + 1][j] = tmp - 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