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