結果

問題 No.54 Happy Hallowe'en
ユーザー snrnsidy
提出日時 2021-05-07 03:40:17
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,247 bytes
コンパイル時間 1,286 ms
コンパイル使用メモリ 132,936 KB
最終ジャッジ日時 2025-01-21 07:50:55
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> 
#include <iomanip>
#include <unordered_map>
#include <memory.h>
#include <unordered_set>
#include <fstream>
#include <random>

using namespace std;

bool dp[2][20001];

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	vector <pair<int, int>> v;
	int n, a, b;

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> a >> b;
		v.push_back(make_pair(a, b));
	}

	sort(v.begin(), v.end());
	
	memset(dp, false, sizeof(dp));
	dp[1][0] = true;

	for (int i = 0; i < n; i++)
	{
		memcpy(dp[0], dp[1], sizeof(dp[1]));
		memset(dp[1], false, sizeof(dp[1]));
		for (int j = 0; j < v[i].second; j++)
		{
			if (dp[0][j] == false)
			{
				continue;
			}
			dp[1][j + v[i].first] = true;
		}
		for (int j = 0; j <= 20000; j++)
		{
			if (dp[0][j])
			{
				dp[1][j] = true;
			}
		}
	}

	int res = 0;

	for (int i = 0; i <= 20000; i++)
	{
		if (dp[1][i])
		{
			res = max(res, i);
		}
	}
	cout << res << '\n';

	return 0;
}
0