結果

問題 No.1583 Building Blocks
ユーザー magstamagsta
提出日時 2021-07-02 19:31:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 1,069 bytes
コンパイル時間 911 ms
コンパイル使用メモリ 90,836 KB
実行使用メモリ 10,900 KB
最終ジャッジ日時 2023-10-12 03:02:07
合計ジャッジ時間 2,775 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 4 ms
5,368 KB
testcase_04 AC 2 ms
4,356 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 3 ms
5,156 KB
testcase_07 AC 4 ms
5,404 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 8 ms
9,388 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 1 ms
4,352 KB
testcase_12 AC 5 ms
6,228 KB
testcase_13 AC 7 ms
7,472 KB
testcase_14 AC 3 ms
4,588 KB
testcase_15 AC 4 ms
5,644 KB
testcase_16 AC 6 ms
7,288 KB
testcase_17 AC 5 ms
6,552 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 10 ms
10,900 KB
testcase_20 AC 3 ms
4,416 KB
testcase_21 AC 3 ms
4,372 KB
testcase_22 AC 3 ms
4,612 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 6 ms
7,228 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 7 ms
8,260 KB
testcase_27 AC 3 ms
4,600 KB
testcase_28 AC 8 ms
9,056 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 6 ms
7,012 KB
testcase_32 AC 4 ms
5,140 KB
testcase_33 AC 11 ms
10,712 KB
testcase_34 AC 1 ms
4,352 KB
testcase_35 AC 4 ms
5,164 KB
testcase_36 AC 8 ms
8,044 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 2 ms
4,352 KB
testcase_39 AC 2 ms
4,352 KB
testcase_40 AC 1 ms
4,352 KB
testcase_41 AC 1 ms
4,348 KB
testcase_42 AC 1 ms
4,352 KB
testcase_43 AC 1 ms
4,348 KB
testcase_44 AC 2 ms
4,348 KB
testcase_45 AC 2 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <vector>
using namespace std;
#define PAIR pair<long long, long long>

int main() {
	long long N; cin >> N;
	vector<long long> w(N), s(N);
	for (int i = 0; i < N; i++) cin >> w[i] >> s[i];

	vector<PAIR> sum(N);
	for (int i = 0; i < N; i++) {
		sum[i].first = w[i] + s[i];
		sum[i].second = w[i];
	}
	sort(sum.begin(), sum.end());

	vector<vector<long long>> dp(N + 1, vector<long long>(N + 1, 1LL << 60));
	for (int i = 0; i <= N; i++) {
		if (i == 0) {
			dp[i][0] = 0;
			continue;
		}
		for (int j = 0; j <= N; j++) {
			if (j == 0) dp[i][j] = 0;
			else {
				if (dp[i - 1][j - 1] > sum[i - 1].first - sum[i - 1].second) {
					dp[i][j] = dp[i - 1][j];
				}
				else {
					dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - 1] + sum[i - 1].second);
				}
			}
		}
	}

	long long max_size = 0;
	for (int i = 1; i <= N; i++) {
		if (dp[N][i] != 1LL << 60) max_size = i;
	}

	cout << max_size << endl;
}
0