結果

問題 No.50 おもちゃ箱
コンテスト
ユーザー 184
提出日時 2014-10-26 23:58:02
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 802 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 445 ms
コンパイル使用メモリ 65,276 KB
実行使用メモリ 7,976 KB
最終ジャッジ日時 2026-06-04 03:24:52
合計ジャッジ時間 2,131 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 4
other AC * 3 WA * 35
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
using namespace std;
//namaega 184

int main(){ 
	int n,m;
	scanf("%d",&n);//%d%d%d%d",&n,&v,&x,&y,&ax,&ay);
	int c[100],v[100];
	for(int i=0;i<n;i++){
		scanf("%d",&c[i]);
	}
	scanf("%d",&m);
	for(int i=0;i<m;i++){
		scanf("%d",&v[i]);
	}
	sort(v,v+m);
	int dp[3001]={};
	dp[0]=1;
	int last=0;
	const int mm=(1<<10);
	int s[mm]={};
	for(int i=0;i<mm;i++){
		if(!s[i]){
			int a=i;
			//printf("%d\n",i);
			for(int j=0;(1<<j)<=i;j++){
				if((i>>j)%2)s[i]+=c[j];
			}
		}
	} 
	sort(s,s+mm);
	int ans=0;
	m--;
	for(int j=mm-1;j>=0;j--){
		if(v[m]>=s[j]){
			ans++;
			j=~j;
			j++;
			m--;
			if(m<0)break;
		}
	} 
	printf("%d\n",m>=0?ans:-1);
	return 0;
}
0