codeforces-670d2Magic Powder-2
Time Limit: 1000MS |
|
Memory Limit: 262144KB |
|
64bit IO Format: %i64d &%i64u |
Submit Status
Description
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 andK (1?≤? n? ≤?100?000,?1?≤? k. ≤?109)-the number of ingredients and the number of grams of the magic powder.
The second line contains the sequence a1,? A2,?...,? An (1?≤? ) Ai? ≤?109), where the I-th number is equal to the number of grams o f Thei-th ingredient, needed to bake one cookie.
The third line contains the sequence b1,? b2,?...,? bn (1?≤? ) bi? ≤?109), where the I-th number is equal to the number of grams of Thei-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.
Sample Input
Input
1 100000000011000000000
Output
2000000000
Input
10 11000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 10000000001 1 1 1 1 1 1 1) 1 1
Output
0
Input
3 12 1 411 3 16
Output
4
Input
4 34 3 5 611 12 14 20
Output
3
Sample Output
Hint
Source
Codeforces Round #350 (Div. 2)
Test instructions: The previous question, is the number opened big, must use two points hait:inf relatively small, therefore must use 3000000000LL on the line
#include <stdio.h> #include <string.h> #include <algorithm> #include <iostream> #define LL Long Long#define INF 0x3f3f3f3f#define N 100010using namespace Std;ll a[n],b[n];int n;ll k;bool judge (ll X) {ll s=k;for (int i=1; i<=n;i++) {if (X*a[i]>=b[i]) s-= (X*a[i]-b[i]), if (s<0) return false;} return true;} int main () {int i;while (scanf ("%d%lld", &n,&k)!=eof) {for (i=1;i<=n;i++) scanf ("%lld", &a[i]); for (i=1;i <=n;i++) scanf ("%lld", &b[i]), if (n==1) {printf ("%lld\n", (K+b[1])/a[1]); continue;} ll L=0,r=3000000000ll,mid,ans;while (l<=r) {mid= (l+r) >>1ll;if (judge (mid)) {L=mid+1;ans=mid;} Elser=mid-1;} printf ("%lld\n", ans);} return 0;}
This is just beginning to write, more trouble.
#include <stdio.h> #include <string.h> #include <algorithm> #include <iostream> #define LL Long Long#define INF 0x3f3f3f3f#define N 100010using namespace std;ll a[n],b[n];struct zz{ll a;ll b;ll c;ll D;} P[n];bool CMP (ZZ a,zz b) {return A.A<B.A;} int N;ll K;bool judge (ll X) {ll s=0;for (int i=1;i<=n;i++) {if (p[i].a<x) s+=p[i].c+ (x-p[i].a-1) *p[i].d;if (s>k) return false;} return true;} int main () {int i;while (scanf ("%d%lld", &n,&k)!=eof) {for (i=1;i<=n;i++) {scanf ("%lld", &a[i]);p [i].d=a [i];} for (i=1;i<=n;i++) scanf ("%lld", &b[i]), if (n==1) {printf ("%lld\n", (K+b[1])/a[1]); continue;} for (i=1;i<=n;i++) {p[i].a=b[i]/a[i];p [i].b=b[i]%a[i];p [i].c=a[i]-p[i].b;} Sort (p+1,p+n+1,cmp); ll L=0,r=3000000000ll,mid,ans;while (l<=r) {mid= (l+r) >>1ll;if (judge (mid)) {l=mid+1; Ans=mid;} Elser=mid-1;} printf ("%lld\n", ans);} return 0;}
Codeforces-670d2 Magic Powder-2 (dichotomy & Simulation)