結果
問題 | No.393 2本の竹 |
ユーザー |
![]() |
提出日時 | 2016-07-16 15:50:32 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 30 ms / 1,000 ms |
コード長 | 1,000 bytes |
コンパイル時間 | 511 ms |
コンパイル使用メモリ | 63,088 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-08 09:26:50 |
合計ジャッジ時間 | 1,519 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 28 |
ソースコード
#include<cstdio> #include<vector> #include<algorithm> #include<iostream> #include<cstring> using namespace std; #define int long long #define rep(i,n) for(int i=0;i<(n);i++) #define pb push_back #define all(v) (v).begin(),(v).end() typedef vector<int>vint; typedef pair<int,int>pint; typedef vector<pint>vpint; int N1,N2; int M; int A[100]; bool dp[2][100010]; void solve(){ cin>>N1>>N2; cin>>M; rep(i,M)cin>>A[i]; sort(A,A+M); memset(dp,0,sizeof(dp)); dp[0][0]=true; int sum=0; rep(i,M+1){ bool update=false; for(int j=0;j<=N1;j++){ if(dp[i&1][j]==false)continue; update=true; if(j+A[i]<=N1)dp[(i+1)&1][j+A[i]]=true; if(sum-j+A[i]<=N2)dp[(i+1)&1][j]=true; dp[i&1][j]=false; } if(!update){ cout<<i-1<<endl; return; } sum+=A[i]; } cout<<M<<endl; } signed main(){ int T;cin>>T; while(T--)solve(); return 0; }