Http://codeforces.com/problemset/problem/670/D2
The term of this problem are the same as the previous one, the only exception-increased restrictions.
Input
The first line contains the positive integers n and k (1≤ n ≤100 000, 1≤ k< /C10>≤109)-the Number of ingredients and the number of grams of the magic powder.
the second line contains the sequence a 1, a 2, ..., a n (1≤ a i ≤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≤ b i ≤109), where the I-th number is equal to the number of grams of 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.
Examplesinput
1 1000000000
1
1000000000
Output
2000000000
input
10 1
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
1 1 1 1 1 1 1 1 1 1
Output
0
input
3 1
2 1 4
11 3 16
Output
4
input
4 3
4 3 5 6
11 12 14 20
Output
3
#include <cstdio>#include<cstring>#include<iostream>#include<cmath>#include<vector>#include<algorithm>#include<string>#include<map>using namespacestd;#defineN 110000#defineMet (A, b) memset (A, B, sizeof (a))#defineINF 0x3f3f3f3fConst Long LongMax =2000000000; typedefLong LongLL; LL A[n], b[n]; LL N, K; ll Judge (ll mid) {ll I, K1=k, k2=K; for(i=1; i<=n; i++) { if(b[i]<a[i]*mid) {K1-= (A[i]*mid-B[i]); if(k1<0) return-1; } } for(i=1; i<=n; i++) { if(B[i]<a[i]* (mid+1) ) {K2-= (a[i]* (mid+1) -B[i]); if(k2<0) return 0; } } return 1;}intMain () { while(SCANF ("%i64d%i64d", &n, &k)! =EOF) {LL i; LL Mid, L=0, r=Max, ans; Met (A,0); Met (b,0); for(i=1; i<=n; i++) scanf ("%i64d", &A[i]); for(i=1; i<=n; i++) scanf ("%i64d", &B[i]); while(l<R) {Mid= (l+r)/2; Ans=Judge (mid); if(ans==0) L= R =mid; if(ans>0) L= Mid +1; if(ans<0) R= Mid-1; } printf ("%i64d\n", L); } return 0;}
Magic Powder-2 (CF 670_d)