結果

問題 No.1583 Building Blocks
ユーザー magstamagsta
提出日時 2021-04-04 12:27:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,069 bytes
コンパイル時間 1,433 ms
コンパイル使用メモリ 90,880 KB
実行使用メモリ 11,028 KB
最終ジャッジ日時 2023-09-11 14:24:14
合計ジャッジ時間 3,711 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 3 ms
5,268 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 4 ms
5,228 KB
testcase_07 AC 4 ms
5,420 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 8 ms
9,060 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 5 ms
5,892 KB
testcase_13 AC 7 ms
7,476 KB
testcase_14 AC 3 ms
4,644 KB
testcase_15 AC 5 ms
5,632 KB
testcase_16 AC 6 ms
7,312 KB
testcase_17 AC 6 ms
6,544 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 10 ms
10,912 KB
testcase_20 AC 3 ms
4,444 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 3 ms
4,648 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 6 ms
7,340 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 7 ms
8,312 KB
testcase_27 AC 3 ms
4,456 KB
testcase_28 AC 8 ms
9,056 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 6 ms
6,992 KB
testcase_32 AC 3 ms
5,144 KB
testcase_33 AC 10 ms
11,028 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 4 ms
5,148 KB
testcase_36 AC 7 ms
8,048 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 1 ms
4,376 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] = 1;
			continue;
		}
		for (int j = 0; j <= N; j++) {
			if (j == 0) dp[i][j] = 1;
			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