結果

問題 No.393 2本の竹
ユーザー latte0119latte0119
提出日時 2016-07-16 15:50:32
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 25 ms / 1,000 ms
コード長 1,000 bytes
コンパイル時間 508 ms
コンパイル使用メモリ 63,512 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-25 21:28:24
合計ジャッジ時間 1,386 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 25 ms
6,940 KB
testcase_10 AC 7 ms
6,940 KB
testcase_11 AC 11 ms
6,944 KB
testcase_12 AC 14 ms
6,940 KB
testcase_13 AC 8 ms
6,940 KB
testcase_14 AC 5 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 3 ms
6,940 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 1 ms
6,944 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 17 ms
6,940 KB
testcase_23 AC 6 ms
6,940 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 22 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0