結果

問題 No.393 2本の竹
ユーザー kotatsugame
提出日時 2020-03-04 08:16:19
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 55 ms / 1,000 ms
コード長 577 bytes
コンパイル時間 644 ms
コンパイル使用メモリ 76,612 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-13 23:30:19
合計ジャッジ時間 1,766 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    6 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int d;
main()
{
	cin>>d;
	for(;d--;)
	{
		int N1,N2;cin>>N1>>N2;
		int M;cin>>M;
		vector<int>A(M);
		for(int i=0;i<M;i++)cin>>A[i];
		sort(A.begin(),A.end());
		vector<bool>dp(N1+1,false);
		dp[0]=true;
		int sum=0;
		int ans=0;
		for(int a:A)
		{
			sum+=a;
			int now=0;
			for(int i=N1;i>=0;i--)
			{
				if(dp[i])
				{
					now=max(now,i);
					if(i+a<=N1)
					{
						dp[i+a]=true;
						now=max(now,i+a);
					}
				}
			}
			if(sum-now<=N2)ans++;
			else break;
		}
		cout<<ans<<endl;
	}
}
0