結果

問題 No.54 Happy Hallowe'en
ユーザー atn112323atn112323
提出日時 2017-01-03 16:12:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 83 ms / 5,000 ms
コード長 560 bytes
コンパイル時間 943 ms
コンパイル使用メモリ 63,840 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-22 10:22:42
合計ジャッジ時間 1,840 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 13 ms
4,380 KB
testcase_05 AC 22 ms
4,380 KB
testcase_06 AC 32 ms
4,376 KB
testcase_07 AC 49 ms
4,380 KB
testcase_08 AC 63 ms
4,380 KB
testcase_09 AC 83 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 81 ms
4,380 KB
testcase_13 AC 82 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>

using namespace std;

const int MAXN = 10000;
const int MAXV = 20000;

int N;
int V[MAXN], T[MAXN];
pair<int, int> P[MAXN];
bool dp[MAXV + 1];

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> V[i] >> T[i];
		P[i] = make_pair(V[i] + T[i], i);
	}
	sort(P, P + N);
	dp[0] = true;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		int j = P[i].second;
		for (int k = T[j] - 1; k >= 0; k--) {
			if (dp[k]) {
				dp[k + V[j]] = true;
				ans = max(ans, k + V[j]);
			}
		}
	}
	cout << ans << endl;
	return 0;
}
0