結果

問題 No.50 おもちゃ箱
ユーザー ttkkggwwttkkggww
提出日時 2022-04-02 03:17:59
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 276 ms / 5,000 ms
コード長 933 bytes
コンパイル時間 4,750 ms
コンパイル使用メモリ 263,068 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-13 03:06:21
合計ジャッジ時間 7,494 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 27 ms
4,384 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 29 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,384 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 132 ms
4,380 KB
testcase_18 AC 15 ms
4,380 KB
testcase_19 AC 52 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 5 ms
4,380 KB
testcase_22 AC 140 ms
4,380 KB
testcase_23 AC 7 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 20 ms
4,376 KB
testcase_29 AC 20 ms
4,380 KB
testcase_30 AC 276 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 39 ms
4,376 KB
testcase_33 AC 143 ms
4,380 KB
testcase_34 AC 2 ms
4,388 KB
testcase_35 AC 75 ms
4,376 KB
testcase_36 AC 40 ms
4,380 KB
testcase_37 AC 25 ms
4,380 KB
testcase_38 AC 14 ms
4,384 KB
testcase_39 AC 20 ms
4,376 KB
testcase_40 AC 150 ms
4,376 KB
testcase_41 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include<atcoder/all>
using namespace atcoder;
using ll = long long;
int n,m;
vector<int> a,b;

void solve(){
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	const int INF = INT_MAX/2;
	int ans = INF;
	do{
		auto A = a;
		auto B = b;
		bool ok = true;
		int cnt = 0;
		bool cntis = true;
		for(int i = 0;i<n;i++){
			if(B.empty()){
				ok = false;
				break;
			}else{
				while(B.size()&&B.back()-A[i]<0){
					B.pop_back();
					cntis = true;
				}
				if(B.empty()){
					ok = false;
					break;
				}
				B.back()-= A[i];
				if(cntis)cnt++;
				cntis = false;
			}
		}
		if(ok)
		ans = min(ans,cnt);
	}while(next_permutation(a.begin(),a.end()));
	if(ans==INF)ans=-1;
	cout<<ans<<endl;
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cin >> n;
	a = vector<int>(n);
	for(auto &i:a)cin >> i;
	cin >> m;
	b = vector<int>(m);
	for(auto &i:b)cin >> i;
	solve();
}
0