結果

問題 No.50 おもちゃ箱
ユーザー karinohitokarinohito
提出日時 2023-10-16 13:52:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 775 bytes
コンパイル時間 2,547 ms
コンパイル使用メモリ 205,560 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-10-16 13:53:02
合計ジャッジ時間 4,309 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)

int main() {
    ll N,M;
    cin>>N;
    vll A(N);
    rep(i,N)cin>>A[i];
    cin>>M;
    vll B(M);
    rep(i,M)cin>>B[i];
    ll an=M+20;
    sort(all(B));
    reverse(all(B));
    do{
        ll k=0;
        ll s=0;
        rep(i,N){
            if(s+A[i]<=B[k]){
                s+=A[i];
            }
            else if(k==M-1){
                k=1e17;
                break;
            }
            else {
                k++;
                s=0;
                i--;
            }
        }
        an=min(an,k+1);
    }while(next_permutation(all(A)));
    cout<<(an<M+1?an:-1)<<endl;
}
0