結果

問題 No.50 おもちゃ箱
ユーザー koprickykopricky
提出日時 2017-08-12 19:40:04
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,666 bytes
コンパイル時間 1,342 ms
コンパイル使用メモリ 160,356 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 07:15:51
合計ジャッジ時間 3,806 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 8 ms
5,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 WA -
testcase_29 AC 7 ms
5,376 KB
testcase_30 WA -
testcase_31 AC 2 ms
5,376 KB
testcase_32 WA -
testcase_33 AC 30 ms
5,376 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 5 ms
5,376 KB
testcase_39 WA -
testcase_40 AC 37 ms
5,376 KB
testcase_41 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl
using namespace std;

typedef pair<int,int>P;

const int MAX_N = 30;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
    }
    int m;
    cin >> m;
    vector<int> b(m);
    rep(i,m){
        cin >> b[i];
    }
    int sma = accumulate(all(a),0);
    int smb = accumulate(all(b),0);
    if(sma > smb){
        cout << "-1\n";
        return 0;
    }
    int ans = INF;
    do {
        int nw = 0,nv = 0;
        int i = 0;
        while(1){
            if(i == n){
                ans = min(ans,nw+1);
                break;
            }
            if(nw == m){
                break;
            }
            if(a[i] + nv <= b[nw]){
                nv += a[i];
                i++;
            }else{
                nw++;
                nv = 0;
            }
        }
    } while (next_permutation(a.begin(), a.end()));
    if(ans == INF){
        cout << "-1\n";
    }else{
        cout << ans << endl;
    }
    return 0;
}
0