3260

/*
DP问题
T分钱,可以由最少的硬币数组成
*/

// include file
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <ctime>

#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <bitset>

#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <list>
#include <functional>

using namespace std;

// typedef
typedef __int64 LL;

// 
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)

#define Z(a,b) ((a)<<(b))
#define Y(a,b) ((a)>>(b))

const double eps = 1e-6;
const double INFf = 1e100;
const int INFi = 1000000000;
const LL INFll = (LL)1<<62;
const double Pi = acos(-1.0);

template<class T> inline T sqr(T a){return a*a;}
template<class T> inline T TMAX(T x,T y)
{
	if(x>y) return x;
	return y;
}
template<class T> inline T TMIN(T x,T y)
{
	if(x<y) return x;
	return y;
}
template<class T> inline T MMAX(T x,T y,T z)
{
	return TMAX(TMAX(x,y),z);
}
template<class T> inline T MMIN(T x,T y,T z)
{
	return TMIN(TMIN(x,y),z);
}
template<class T> inline void SWAP(T &x,T &y)
{
	T t = x;
	x = y;
	y = t;
}


// code begin
int N,T;
struct node
{
	int v;
	int c;
};
node pac[110];
int DP[14400];
int DP2[14400];
int main()
{
	read;
	write;
	

	while(scanf("%d %d",&N,&T)==2)
	{
		for(int i=0;i<N;i++)
		{
			scanf("%d",&pac[i].v);
		}
		for(int i=0;i<N;i++)
		{
			scanf("%d",&pac[i].c);
		}

		
		int up = 14400;
		fill(DP,DP+up,INFi);
		DP[0] = 0;
		for(int i=0;i<N;i++)
		{
			//
			int begin = 1;
			while(begin<pac[i].c)
			{
				// zeroone
				for(int j=up-1;j>=0;j--)
				{
					if(j-pac[i].v*begin<0) break;
					DP[j] = TMIN(DP[j],DP[j-pac[i].v*begin]+begin);
				}

				pac[i].c-=begin;
				begin*=2;
			}
			//zeroone

			for(int j=up-1;j>=0;j--)
			{
				if(j-pac[i].v*pac[i].c<0) break;
				DP[j] = TMIN(DP[j],DP[j-pac[i].v*pac[i].c]+pac[i].c);
			}
		}
		
		fill(DP2,DP2+14400,INFi);
		DP2[0] = 0;
		for(int i=0;i<N;i++)
		{
			for(int j=0;j<14400;j++)
			{
				if(j+pac[i].v>=14400) break;
				DP2[j+pac[i].v] = TMIN(DP2[j+pac[i].v],DP2[j]+1);
			}
		}

		int ans = INFi;
		for(int i=T;i<up;i++)
		{
			if(DP[i]+DP2[i-T]<ans)
				ans=DP[i]+DP2[i-T];
		}
		if(ans!=INFi) printf("%d\n",ans);
		else printf("-1\n");
	}
	return 0;
}

posted @ 2011-04-19 22:29  AC2012  阅读(186)  评论(0编辑  收藏  举报