結果

問題 No.50 おもちゃ箱
ユーザー btkbtk
提出日時 2017-06-20 17:05:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 235 ms / 5,000 ms
コード長 1,398 bytes
コンパイル時間 1,678 ms
コンパイル使用メモリ 171,472 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-08 04:50:53
合計ジャッジ時間 7,040 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 228 ms
4,376 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 183 ms
4,384 KB
testcase_06 AC 20 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 159 ms
4,380 KB
testcase_18 AC 17 ms
4,380 KB
testcase_19 AC 232 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 20 ms
4,376 KB
testcase_22 AC 193 ms
4,380 KB
testcase_23 AC 13 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 21 ms
4,376 KB
testcase_28 AC 204 ms
4,380 KB
testcase_29 AC 202 ms
4,376 KB
testcase_30 AC 169 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 212 ms
4,380 KB
testcase_33 AC 197 ms
4,380 KB
testcase_34 AC 217 ms
4,380 KB
testcase_35 AC 213 ms
4,380 KB
testcase_36 AC 222 ms
4,376 KB
testcase_37 AC 190 ms
4,380 KB
testcase_38 AC 188 ms
4,380 KB
testcase_39 AC 217 ms
4,376 KB
testcase_40 AC 235 ms
4,380 KB
testcase_41 AC 190 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define DEBUG if(0)
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
    
int main(){
    int N,M;
    cin>>N;
    vector<int> a(N);
    cin>>a;
    cin>>M;
    vector<int> b(M);
    cin>>b;
    sort(ALL(b));
    reverse(ALL(b));
    vector<int> ord(N);
    iota(ALL(ord),0);
    int res=100;
    do{
        auto c= b;
        int id=0;
        bool flag=true;
        REP(i,N){
            while(id<M){
                if(c[id]>=a[ord[i]])break;
                id++;
            }
            if(id==M){
                flag=false;
                break;
            }
            c[id]-=a[ord[i]];
        }
        if(flag)chmin(res,id+1);
    }while(next_permutation(ALL(ord)));
    if(res==100)res=-1;
    cout<<res<<endl;
    return 0;
}
0