Greedy
James likes to raise chicks, while chicks like to eat millet. James is greedy. He hopes to raise only different types of chicks, and the chicks are greedy. Besides eating fixed AI grains of millet, he also wants to eat more bi * s grains of millet.
Xiao Ming has m (0 <= m <= 10 ^ 9) grains of millet per day to feed chicks. There are N (0 <= n <= 1000) Types of chicks. How many chicks can James raise at most?
Input
Multiple groups of data. Please read at the end of the file
The first line, integer n, m, are separated by spaces, followed by two rows. The first line is n integer AI, and the second line is n integer bi.
Both AI and Bi are in the int range.
Output
A row has an integer (s.
Sample Input
2 414 09 4
Sample output
2
Source 13th Beijing Normal University Program Design Competition finals author
DLJ
Reprinted please indicate the source: http://blog.csdn.net/u010579068/article/details/45607059
Question link: http://www.bnuoj.com/bnuoj/problem_show.php? PID = 1, 49103
Indicates that wa is performed 8 times... Binary + greedy
#include <iostream>#include <stdio.h>#include <string.h>#include <stack>#include <queue>#include <map>#include <set>#include <vector>#include <math.h>#include <algorithm>using namespace std;#define ls 2*i#define rs 2*i+1#define up(i,x,y) for(i=x;i<=y;i++)#define down(i,x,y) for(i=x;i>=y;i--)#define mem(a,x) memset(a,x,sizeof(a))#define w(a) while(a)#define LL long longconst double pi = acos(-1.0);#define N 1005#define mod 19999997const int INF = 0x3f3f3f3f;#define exp 1e-8LL n,m;LL a[N],b[N],c[N];LL bin(LL x){ LL i,j,k,ans = 0; up(i,0,n-1) { c[i] = a[i]+b[i]*x; } sort(c,c+n); up(i,0,x-1) ans+=c[i]; return ans<=m;}int main(){ LL i,j,k; w(~scanf("%lld%lld",&n,&m)) { up(i,0,n-1) scanf("%lld",&a[i]); up(i,0,n-1) scanf("%lld",&b[i]); LL l=0,r = n,flag = 0; while(l<r) { LL mid = (l+r+1)/2; if(bin(mid)) l=mid; else r=mid-1; } printf("%lld\n",l); } return 0;}
Greedy (bnuoj49103 + binary + greedy)