贪心(bnuoj49103+二分+贪心)

贪心

 

小明喜欢养小鸡,小鸡喜欢吃小米。小明很贪心,希望养s只不同种类的小鸡,小鸡也很贪心,每天除了吃固定的ai粒小米外,还想多吃bi*s粒小米。

小明每天有M(0<=M<=10^9)粒小米可以喂小鸡,小鸡共有N(0<=N<=1000)种。问小明最多可以养多少只小鸡?

 

Input

多组数据,请读到文件尾

第一行,整数N,M,以空格分隔,之后两行,第一行为N个整数ai,第二行为N个整数bi。

ai、bi都在int范围内

Output

一行一个整数,s。

 

Sample Input

2 41	
4 0
9 4

Sample Output

2

Source

Author

dlj

 

 

转载请注明出处:http://blog.csdn.net/u010579068/article/details/45607059

 

题目链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=49103

 

表示WA了8次。。。二分+贪心

 

 

#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 long
const double pi = acos(-1.0);
#define N 1005
#define mod 19999997
const int INF = 0x3f3f3f3f;
#define exp 1e-8

LL 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;
}


 

 

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值