Codeforces 670d2 Magic Powder-2 Two-point answer

Source: Internet
Author: User

Waking up on the morning, Apollinaria decided to bake cookies. To bake one cookies, she needs n ingredients, and for each ingredient she knows the value ai-how many grams of this ingre Dient one needs to bake a cookie. To prepare one cookie Apollinaria needs to use all n ingredients.

Apollinaria has bi gram of the i-th ingredient. Also She has k grams of a magic powder. Each gram of magic powder can is turned to exactly 1 gram of any of the n ingredients and can is used for baking cookies.

Your task is to determine the maximum number of cookies, which Apollinaria are able to bake using the ingredients that she Has and the magic powder.

Input

The first line contains the positive integers n and K (1?≤?n?≤?100?000,?1?≤?k?≤?109)-the number of ingredients and the N Umber of grams of the magic powder.

The second line contains the sequence a1,?a2,?...,? A (1?≤?ai?≤?109), where the i-th number is equal to the number of grams Of the i-th ingredient, needed to bake one cookie.

The third line contains the sequence b1,?b2,?...,? bn (1?≤?bi?≤?109), where the i-th number was equal to the number of grams o f The i-th ingredient, which Apollinaria has.
Output

Print the maximum number of cookies, which Apollinaria would be a able to bake using the ingredients that she have and the mag IC Powder.

Analysis:
Two-point answer can be.

#include <bits/stdc++.h>using namespace STD;typedef Long LongllConst intn=1e5+9; ll A[n],b[n];intN,k;BOOLOk (ll x) {ll num=k; for(intI=0; i<n;i++) {ll t=b[i]-x*a[i];if(t<0) {num+=t;if(num<0)return 0; }    }return 1;}intMain () {scanf("%d%d", &n,&k); for(intI=0; i<n;i++)scanf("%i64d", &a[i]); for(intI=0; i<n;i++)scanf("%i64d", &b[i]); ll l=0, r=2e9+9; while(L<r) {intm=l+ (r-l+1)/2;if(OK (m)) l=m;Elser=m-1; }printf("%d\n", l);}

Codeforces 670d2 Magic Powder-2 Two-point answer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.