結果

問題 No.393 2本の竹
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2016-07-12 19:42:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 144 ms / 1,000 ms
コード長 1,503 bytes
コンパイル時間 733 ms
コンパイル使用メモリ 91,520 KB
実行使用メモリ 27,476 KB
最終ジャッジ日時 2023-08-08 00:10:47
合計ジャッジ時間 4,377 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
27,264 KB
testcase_01 AC 40 ms
27,156 KB
testcase_02 AC 40 ms
27,200 KB
testcase_03 AC 42 ms
27,476 KB
testcase_04 AC 41 ms
27,196 KB
testcase_05 AC 41 ms
27,160 KB
testcase_06 AC 42 ms
27,196 KB
testcase_07 AC 41 ms
27,160 KB
testcase_08 AC 42 ms
27,260 KB
testcase_09 AC 144 ms
27,180 KB
testcase_10 AC 68 ms
27,140 KB
testcase_11 AC 81 ms
27,196 KB
testcase_12 AC 87 ms
27,464 KB
testcase_13 AC 69 ms
27,416 KB
testcase_14 AC 58 ms
27,220 KB
testcase_15 AC 23 ms
27,212 KB
testcase_16 AC 58 ms
27,160 KB
testcase_17 AC 41 ms
27,336 KB
testcase_18 AC 40 ms
27,260 KB
testcase_19 AC 31 ms
27,180 KB
testcase_20 AC 39 ms
27,328 KB
testcase_21 AC 40 ms
27,216 KB
testcase_22 AC 96 ms
27,200 KB
testcase_23 AC 66 ms
27,328 KB
testcase_24 AC 41 ms
27,192 KB
testcase_25 AC 38 ms
27,416 KB
testcase_26 AC 34 ms
27,140 KB
testcase_27 AC 125 ms
27,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <list>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(d) string(1,d)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int dp[61][100005];

int f(int a, int b, vector<int> &v) {
  sort(all(v));
  rep(i,0,61)rep(j,0,100005)dp[i][j]=1000000000;
  if(v[0]<=a){
    dp[0][v[0]]=0;
  }
  if(v[0]<=b){
    dp[0][0]=v[0];
  }
  rep(i,1,v.sz){
    rep(j,0,a+1){
      if(j+v[i]<=a){
        dp[i][j+v[i]]=min(dp[i][j+v[i]],dp[i-1][j]);
      }
      if(dp[i-1][j]+v[i]<=b){
        dp[i][j] = min(dp[i][j],dp[i-1][j]+v[i]);
      }
    }
  }
  int mx = 0;
  rep(i,0,v.sz){
    rep(j,0,a+1){
      if(dp[i][j]<=b){
        mx = max(mx,i+1);
      }
    }
  }
  return mx;
}

int main() {
  int n;
  cin>>n;
  rep(i,0,n){
    int a,b;
    cin>>a>>b;
    int m;
    cin>>m;
    vector<int> v;
    rep(i,0,m){
      int c;
      cin>>c;
      v.pb(c);
    }
    cout << f(a,b,v) << endl;
  }
  return 0;
}
0