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-;
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的更多相关文章
- Codeforces 670D1. Magic Powder - 1 暴力
D1. Magic Powder - 1 time limit per test: 1 second memory limit per test: 256 megabytes input: stand ...
- CodeForces 670D2 Magic Powder 二分
D2. Magic Powder - 2 The term of this problem is the same as the previous one, the only exception — ...
- CodeForces 670D2 Magic Powder - 2 (二分)
题意:今天我们要来造房子.造这个房子需要n种原料,每造一个房子需要第i种原料ai个.现在你有第i种原料bi个.此外,你还有一种特殊的原料k个, 每个特殊原料可以当作任意一个其它原料使用.那么问题来了, ...
- Codeforces Round #350 (Div. 2) D1. Magic Powder - 1 二分
D1. Magic Powder - 1 题目连接: http://www.codeforces.com/contest/670/problem/D1 Description This problem ...
- 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 ...
- 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 ...
- Magic Powder - 2 (CF 670_D)
http://codeforces.com/problemset/problem/670/D2 The term of this problem is the same as the previous ...
- D2 Magic Powder -1/- 2---cf#350D2(二分)
题目链接:http://codeforces.com/contest/670/problem/D2 This problem is given in two versions that differ ...
- Codefroces D2. Magic Powder - 2(二分)
http://codeforces.com/problemset/problem/670/D2 http://codeforces.com/problemset/problem/670/D1 time ...
随机推荐
- 6 MySQL视图
目录: 1. 视图概述 1.1 为什么引入视图 1.2 什么是视图 1.3 视图的好处 1.4 视图的分类 2. 视图的建立和删除 3. 实验 1. 视图概述 1.1 为什么引入视图[1] 问题:假如 ...
- 用邻接表或vector实现存边以及具体如何调用[模板]
存边: 对于指针实现的邻接表: struct edge{ int from,next,to,w; }E[maxn]; int head[maxn],tot=0;//head初始化为-1: void a ...
- Pi
Math]Pi 数学知识忘地太快,在博客记录一下pi的生成. 100 Decimal places 3.1415926535897932384626433832795028841971693993 ...
- ubuntu 下面手动安装jdk
ubuntu 下面手动安装jdk 刚才在ubuntu安装jdk和eclipse,感觉主要安装jdk比较麻烦,记录一下笔记以备后面查看 先在官网上下载jdk的tar包:http://www.oracle ...
- python学习之路四(类和对象1)
#encoding:utf-8 ''' Created on 2013-7-29 @author: lixingle ''' #CLass............................... ...
- DDD社区官网
DDD社区官网上一篇关于聚合设计的几个原则的简单讨论: 聚合是用来封装真正的不变性,而不是简单的将对象组合在一起 聚合应尽量设计的小 聚合之间通过ID关联 聚合内强一致性,聚合之间最终一致性 从聚合和 ...
- Myeclipse 10 for mac 破解版下载安装及破解方法
下载地址:http://pan.baidu.com/share/link?shareid=463687&uk=1798617416 解压下载好的压缩包Myeclipse 10 for mac+ ...
- Cocoa框架
Cocoa提供了用于存放数字和字符串的通用数据类型的实际的类.非正式地可以将这些称为值类或基本值类. Cocoa框架本身封装了三个独立的框架:Foundation基本框架.AppKit框架和核心数据框 ...
- javascript操作写入txt文件及消息: Automation 服务器不能创建对象问题
简单的写入txt代码: function WriteTxt() { var fso, tf; fso = new ActiveXObject("Scripting.Fil ...
- memcache研究
memcache研究 最近开发了一个数据库,该数据库是利用共享内存做的,测试了下增删改查的性能,想与memcached数据库做个对比,故研究下memcached. 那什么是memcached? mem ...