結果
| 問題 | No.50 おもちゃ箱 |
| コンテスト | |
| ユーザー |
btk
|
| 提出日時 | 2017-06-20 17:05:00 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 226 ms / 5,000 ms |
| コード長 | 1,398 bytes |
| 記録 | |
| コンパイル時間 | 1,925 ms |
| コンパイル使用メモリ | 173,464 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-25 22:05:33 |
| 合計ジャッジ時間 | 6,905 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 38 |
ソースコード
#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;
}
btk