CODEFORCES-670D2 Magic 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 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, ..., an (1≤ai≤109), where the i-th number was equal to the number of gram s 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 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.
Sample Input Input
1 1000000000
1
1000000000
Output
2000000000
Input
1
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000< C5/>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
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 100010
using 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;
}
else
r=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 100010 using 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;
} else r=mid-1; } priNTF ("%lld\n", ans);
} return 0; }