分析:f[i][j] 表示当前用了i个瓶子,共堆出来j的容量的最大剩余.
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<stack>
#include<queue>
#define INF 4557430888798830400ll
#define eps 1e-9
#define MAXN 0x3f
#define N 105
using namespace std;
int n,k,ans,tot,tot_b,cnt,a[N],s[N],b[N],f[N][10005];
int main()
{
scanf("%d",&n);
for(int i = 1;i <= n;i++)
{
scanf("%d",&a[i]);
tot += a[i];
}
for(int i = 1;i <= n;i++)
{
scanf("%d",&b[i]);
s[i] = b[i];
tot_b += b[i];
}
sort(s+1,s+1+n);
for(int i = 1;i <= n && cnt < tot;i++)
{
k++;
cnt += s[n-i+1];
}
memset(f,-1,sizeof(f));
f[0][0] = 0,ans = tot;
for(int i = 1;i <= n;i++)
for(int j = tot_b;j >= b[i];j--)
for(int l = k;l;l--)
if(f[l-1][j-b[i]] >= 0) f[l][j] = max(f[l][j],f[l-1][j-b[i]] + a[i]);
for(int j = tot_b;j >= tot;j--)
ans = min(ans,tot - f[k][j]);
printf("%d %d\n",k,ans);
}