二分。

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

#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-;
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=;
while(!isdigit(c)) c=getchar();
while(isdigit(c)) {x=x*+c-''; c=getchar();}
} const int maxn=;
LL k,a[maxn],b[maxn];
int n; bool check(LL x)
{
LL sum=;
for(int i=;i<=n;i++)
{
if(a[i]*x<=b[i]) continue;
sum=sum+a[i]*x-b[i];
if(sum>k) return ;
}
if(sum<=k) return ;
return ;
} int main()
{
scanf("%d%lld",&n,&k);
for(int i=;i<=n;i++) scanf("%lld",&a[i]);
for(int i=;i<=n;i++) scanf("%lld",&b[i]); LL L=,R=3e9,ans;
while(L<=R)
{
LL mid=(L+R)/;
if(check(mid)) L=mid+,ans=mid;
else R=mid-;
}
printf("%lld\n",ans); return ;
}

CodeForces 670D Magic Powder的更多相关文章

  1. Codeforces 670D1. Magic Powder - 1 暴力

    D1. Magic Powder - 1 time limit per test: 1 second memory limit per test: 256 megabytes input: stand ...

  2. CodeForces 670D2 Magic Powder 二分

    D2. Magic Powder - 2 The term of this problem is the same as the previous one, the only exception — ...

  3. CodeForces 670D2 Magic Powder - 2 (二分)

    题意:今天我们要来造房子.造这个房子需要n种原料,每造一个房子需要第i种原料ai个.现在你有第i种原料bi个.此外,你还有一种特殊的原料k个, 每个特殊原料可以当作任意一个其它原料使用.那么问题来了, ...

  4. Codeforces Round #350 (Div. 2) D1. Magic Powder - 1 二分

    D1. Magic Powder - 1 题目连接: http://www.codeforces.com/contest/670/problem/D1 Description This problem ...

  5. Codeforces Round #350 (Div. 2)_D2 - Magic Powder - 2

    D2. Magic Powder - 2 time limit per test 1 second memory limit per test 256 megabytes input standard ...

  6. codeforces 350 div2 D Magic Powder - 2 二分

    D2. Magic Powder - 2 time limit per test 1 second memory limit per test 256 megabytes input standard ...

  7. Magic Powder - 2 (CF 670_D)

    http://codeforces.com/problemset/problem/670/D2 The term of this problem is the same as the previous ...

  8. D2 Magic Powder -1/- 2---cf#350D2(二分)

    题目链接:http://codeforces.com/contest/670/problem/D2 This problem is given in two versions that differ ...

  9. Codefroces D2. Magic Powder - 2(二分)

    http://codeforces.com/problemset/problem/670/D2 http://codeforces.com/problemset/problem/670/D1 time ...

随机推荐

  1. C++构造 下一个排列 的函数

    今天围观刘汝佳神犇的白书发现了一个好用的函数: next_permutation(); 可以用于可重, 或者不可重集, 寻找下一个排列. 时间复杂度尚不明. //适用于不可重和可重集的排列. # in ...

  2. jquery上传控件uploadify使用备忘

    我简单修改了js和样式,效果如下 使用起来也是超简单,将文件下载并解压到你网站目录下,然后 .在使用位置插入代码 ============================= <iframe wi ...

  3. 迷你MVVM框架 avalonjs 0.95发布

    迷你MVVM框架 avalonjs 0.95发布 本版本最主要的改进是ms-with 深层绑定的实现,至少,avalon1.0所有重要的feature已经开发完毕,之后就是小补小漏,性能优化了. ms ...

  4. 【C#】Smtp发送邮件

    class SmtpEmail { SmtpClient smtpclient; MailMessage msg; Attachment attachment; public void sendMai ...

  5. jQuery的delegate

    jQuery的delegate 在网页开发的过程中经常遇到的一个需求就是点击一div内部做某些操作,而点击页面其它地方隐藏该div.比如很多导航菜单,当菜单展开的时候,就会要求点击页面其它非菜单地方, ...

  6. MapXtreme+Asp.net 动态轨迹

    MapXtreme+Asp.net 动态轨迹(请求大神指点)   功能简介:在MapXtreme+Asp.net的环境下实现轨迹回放功能,经过两天的努力基本实现此功能.但还有部分问题需要解决,求大神们 ...

  7. 4605 Magic Ball Game

    先离线记录所有询问,然后用dfs在线记录当前节点的所有父亲结点,父亲结点分为两类,一个从左边过来,一个从右边过来,分别开一个数组. 数据需要离散化,刚开始用lower_bound写,一直wa..,用二 ...

  8. gsoap:实现线程池处理时获取到客户端的ip

    问题: 在使用线程池处理客户端请求时发现不能获取到客户端的ip! 原因:     由于在server_loop注循环中只把连接字sock加到queue队列中,并没有客户端IP,所以每一次queue回调 ...

  9. [COM/ATL]组件、对象、MFC、ATL的区别

    组件(Component)和对象(Object)之间的区别 先明确组件(Component)和对象(Object)之间的区别.组件是一个可重用的模块,它是由一 组处理过程.数据封装和用户接口组成的业务 ...

  10. sharepoint 2013 自定义列表eventhandle权限控制

    记录一下如何在sharepoint server 2013自定义列表中,使用eventhandle控制自定义列表custom list的条目item权限. ///<summary> /// ...