結果

問題 No.54 Happy Hallowe'en
ユーザー cielciel
提出日時 2015-04-09 12:08:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 29 ms / 5,000 ms
コード長 630 bytes
コンパイル時間 387 ms
コンパイル使用メモリ 50,788 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-17 18:59:01
合計ジャッジ時間 1,489 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <vector>
#include <algorithm>
#include <cstdio>
int main(){
	int n,vmax=0,tmax=0;
	scanf("%d",&n);
	std::vector<std::pair<int,int> >v(n);
	for(int i=0;i<n;i++){
		scanf("%d%d",&v[i].first,&v[i].second);
		if(vmax<v[i].first)vmax=v[i].first;
		if(tmax<v[i].second)tmax=v[i].second;
	}
	std::sort(v.begin(),v.end(),[](std::pair<int,int> &a,std::pair<int,int> &b)->bool{return a.first+a.second<b.first+b.second;});
	std::vector<int>bag(tmax+vmax+1);
	bag[0]=1;
	for(int i=0;i<n;i++){
		for(int j=v[i].second-1;j>=0;j--)bag[j+v[i].first]|=bag[j];
	}
	for(int i=tmax+vmax;i>=0;i--)if(bag[i]){
		printf("%d\n",i);
		break;
	}
}
0