結果

問題 No.50 おもちゃ箱
ユーザー 0w10w1
提出日時 2016-12-13 11:27:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 127 ms / 5,000 ms
コード長 1,362 bytes
コンパイル時間 1,691 ms
コンパイル使用メモリ 173,112 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-08 04:49:27
合計ジャッジ時間 3,784 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 14 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 12 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 46 ms
4,376 KB
testcase_18 AC 6 ms
4,380 KB
testcase_19 AC 24 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 51 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 11 ms
4,380 KB
testcase_29 AC 11 ms
4,380 KB
testcase_30 AC 127 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 20 ms
4,380 KB
testcase_33 AC 70 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 40 ms
4,376 KB
testcase_36 AC 21 ms
4,376 KB
testcase_37 AC 14 ms
4,376 KB
testcase_38 AC 8 ms
4,376 KB
testcase_39 AC 10 ms
4,380 KB
testcase_40 AC 59 ms
4,380 KB
testcase_41 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef long long ll;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef pair< int, int > pii;
typedef vector< pii > vp;
typedef vector< double > vd;
typedef vector< vd > vvd;
typedef vector< string > vs;

template< class T1, class T2 >
int upmin( T1 &x, T2 v ){
  if( x > v ){
    x = v;
    return 1;
  }
  return 0;
}

template< class T1, class T2 >
int upmax( T1 &x, T2 v ){
  if( x < v ){
    x = v;
    return 1;
  }
  return 0;
}

const int INF = 0x3f3f3f3f;

int N;
vi A;
int M;
vi B;

void init(){
  cin >> N;
  A = vi( N );
  for( int i = 0; i < N; ++i )
    cin >> A[ i ];
  cin >> M;
  B = vi( M );
  for( int i = 0; i < M; ++i )
    cin >> B[ i ];
}

int ans = INF;

void preprocess(){
  sort( B.begin(), B.end(), greater< int >() );
  sort( A.begin(), A.end() );
  do{
    int ptr_a = 0;
    for( int i = 0; i < M; ++i ){
      int s = B[ i ];
      while( ptr_a < N and s >= A[ ptr_a ] )
        s -= A[ ptr_a++ ];
      if( ptr_a == N ){
        upmin( ans, i + 1 );
        break;
      }
    }
  } while( next_permutation( A.begin(), A.end() ) );
}

void solve(){
  if( ans == INF )
    cout << -1 << endl;
  else
    cout << ans << endl;
}

signed main(){
  ios::sync_with_stdio( 0 );
  init();
  preprocess();
  solve();
  return 0;
}
0