貪心(bnuoj49103+二分+貪心),貪心bnuoj49103

來源:互聯網
上載者:User

貪心(bnuoj49103+二分+貪心),貪心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 414 09 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 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;}


 

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.