結果

問題 No.54 Happy Hallowe'en
ユーザー Ysmr_RyYsmr_Ry
提出日時 2014-12-14 10:44:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 61 ms / 5,000 ms
コード長 850 bytes
コンパイル時間 316 ms
コンパイル使用メモリ 44,152 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-05 20:05:59
合計ジャッジ時間 1,702 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 10 ms
4,380 KB
testcase_05 AC 17 ms
4,376 KB
testcase_06 AC 24 ms
4,380 KB
testcase_07 AC 36 ms
4,380 KB
testcase_08 AC 48 ms
4,380 KB
testcase_09 AC 58 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 61 ms
4,380 KB
testcase_13 AC 57 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<utility>
#define rep(i,a) for(int i=0;i<(a);++i)
#define repd(i,a) for(int i=(a);i>=0;--i)
#define clr(a,v) memset((a),(v),sizeof(a))

typedef std::pair<int, int> P;

const int MAX_N = 10000;

int N;
P ps[MAX_N];
bool dp[MAX_N+1];

int main()
{
	scanf( "%d", &N );
	rep( i, N )
	{
		int V, T;
		scanf( "%d%d", &V, &T );
		ps[i] = P( V, T );
	}

	std::sort( ps, ps+N, []( const P &lhs, const P &rhs ){ return lhs.first+lhs.second < rhs.first+rhs.second; }  );
	clr( dp, false );
	dp[0] = true;

	int ans = 0;
	rep( i, N )
	{
		repd( j, ps[i].second-1 )
		{
			if( !dp[j] )
				continue;

			ans = std::max( ans, j+ps[i].first );

			if( j+ps[i].first <= MAX_N )
				dp[j+ps[i].first] |= dp[j];
		}
	}

	printf( "%d\n", ans );

	return 0;
}
0