CodeForces 670D Magic Powder

Posted Fighting Heart

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CodeForces 670D Magic Powder相关的知识,希望对你有一定的参考价值。

二分。

二分一下答案,然后验证一下。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-6;
void File()
{
    freopen("D:\\in.txt","r",stdin);
    freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
    char c=getchar(); x=0;
    while(!isdigit(c)) c=getchar();
    while(isdigit(c)) {x=x*10+c-0; c=getchar();}
}

const int maxn=100010;
LL k,a[maxn],b[maxn];
int n;

bool check(LL x)
{
    LL sum=0;
    for(int i=1;i<=n;i++)
    {
        if(a[i]*x<=b[i]) continue;
        sum=sum+a[i]*x-b[i];
        if(sum>k) return 0;
    }
    if(sum<=k) return 1;
    return 0;
}

int main()
{
    scanf("%d%lld",&n,&k);
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    for(int i=1;i<=n;i++) scanf("%lld",&b[i]);

    LL L=0,R=3e9,ans;
    while(L<=R)
    {
        LL mid=(L+R)/2;
        if(check(mid)) L=mid+1,ans=mid;
        else R=mid-1;
    }
    printf("%lld\n",ans);

    return 0;
}

 

以上是关于CodeForces 670D Magic Powder的主要内容,如果未能解决你的问题,请参考以下文章

?????????????????????Codeforces Educational Codeforces Round 9 Magic Matrix

Codeforces 670D. Magic Powder

Dima and Magic Guitar CodeForces - 366E

Magic Stones CodeForces - 1110E (思维+差分)

codeforces 711B - Chris and Magic Square

codeforces 632F. Magic Matrix