結果

問題 No.1583 Building Blocks
ユーザー magstamagsta
提出日時 2021-04-04 16:01:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 1,069 bytes
コンパイル時間 1,054 ms
コンパイル使用メモリ 91,076 KB
実行使用メモリ 10,984 KB
最終ジャッジ日時 2023-10-12 03:01:42
合計ジャッジ時間 3,179 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 4 ms
5,360 KB
testcase_04 AC 2 ms
4,356 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 4 ms
5,120 KB
testcase_07 AC 5 ms
5,424 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 9 ms
9,392 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 5 ms
6,260 KB
testcase_13 AC 7 ms
7,844 KB
testcase_14 AC 3 ms
4,620 KB
testcase_15 AC 4 ms
5,760 KB
testcase_16 AC 7 ms
7,500 KB
testcase_17 AC 5 ms
6,472 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 10 ms
10,880 KB
testcase_20 AC 3 ms
4,556 KB
testcase_21 AC 3 ms
4,484 KB
testcase_22 AC 3 ms
4,644 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 6 ms
7,204 KB
testcase_25 AC 1 ms
4,352 KB
testcase_26 AC 8 ms
8,404 KB
testcase_27 AC 3 ms
4,428 KB
testcase_28 AC 8 ms
9,056 KB
testcase_29 AC 2 ms
4,352 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 7 ms
6,920 KB
testcase_32 AC 4 ms
5,212 KB
testcase_33 AC 11 ms
10,984 KB
testcase_34 AC 1 ms
4,352 KB
testcase_35 AC 4 ms
5,208 KB
testcase_36 AC 7 ms
8,108 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 2 ms
4,348 KB
testcase_41 AC 1 ms
4,348 KB
testcase_42 AC 2 ms
4,348 KB
testcase_43 AC 2 ms
4,352 KB
testcase_44 AC 1 ms
4,352 KB
testcase_45 AC 1 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