結果
問題 |
No.50 おもちゃ箱
|
ユーザー |
|
提出日時 | 2020-06-07 08:50:26 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 577 bytes |
コンパイル時間 | 2,403 ms |
コンパイル使用メモリ | 193,924 KB |
最終ジャッジ日時 | 2025-01-10 23:40:37 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 29 WA * 9 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:27:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 27 | scanf("%d",&n); | ~~~~~^~~~~~~~~ main.cpp:28:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 28 | rep(i,n) scanf("%d",&a[i]); | ~~~~~^~~~~~~~~~~~ main.cpp:29:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 29 | scanf("%d",&m); | ~~~~~^~~~~~~~~ main.cpp:30:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 30 | rep(j,m) scanf("%d",&b[j]); | ~~~~~^~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; const int INF=1<<29; int n,m,a[10],b[10]; int cap[10]; int dfs(int i){ if(i==n) return m-count(cap,cap+m,0); int res=INF; rep(j,m) if(cap[j]+a[i]<=b[j]) { cap[j]+=a[i]; res=min(res,dfs(i+1)); cap[j]-=a[i]; if(cap[j]==0) break; } return res; } int main(){ scanf("%d",&n); rep(i,n) scanf("%d",&a[i]); scanf("%d",&m); rep(j,m) scanf("%d",&b[j]); sort(a,a+n,greater<int>()); sort(b,b+m,greater<int>()); int ans=dfs(0); printf("%d\n",ans<INF?ans:-1); return 0; }