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 ...
随机推荐
- MvcMovieStore实例 教程
转原创:MvcMovieStore 实例教程(新概念版:mvc5.0,EF6.01)-初露锋芒 如需转载,请注明出处:http://www.cnblogs.com/DoduNet/ 最近趁业余时间,把 ...
- 哞哞快的 C# 高斯模糊实现
冲动来自于 bing best 这个小工具,非常短小精干,里边的设置界面非常精美而且背景是一张模糊效果的图片,十分养眼,遂想,收集一下实现方式放到类库里以后肯定用得上.一通百度.谷歌.博客园,换了好多 ...
- FAQ:仓储实现为什么在基础设施层?
FAQ:仓储实现为什么在基础设施层? 目录 问答部分参考文章 问答部分返回目录 问: 仓储实现为什么在基础设施层? 答: 领域模型包含三种元素:实体.值对象和服务,这三种元素都可以以某种形式使用仓储, ...
- HDU--杭电--3415--Max Sum of Max-K-sub-sequence--暴力或单调队列
Max Sum of Max-K-sub-sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- 把事务封装成类似Serializable用法的特性
把事务封装成类似Serializable用法的特性 最近几天上班没事可做就想着整理常用的类库方法,验证.消息.分页.模版引擎.数据库操作.ini操作.文本操作.xml操作等,最后就是现在这个事务特性. ...
- HttpMessageHandler管道[上篇]
HttpMessageHandler管道[上篇] 整个ASP.NET Web API服务端框架采用管道式设计,这个用于“处理请求.响应回复”的管道本质上就是一组HttpMessageHandler的有 ...
- “MVC+Nhibernate+Jquery-EasyUI”信息发布系统 第二篇(数据库结构、登录窗口、以及主界面)
“MVC+Nhibernate+Jquery-EasyUI”信息发布系统 第二篇(数据库结构.登录窗口.以及主界面) 一.在上一篇文章中,主要说的就是把主框架搭建起来,并且Nhibernate能达到增 ...
- 用友CDM系统“货位间商品移库单(一步)”表体增加“货位可用数量”字段,根据表头的选择的货位自动带出数值
系统控制台——业务单据定制——货位间商品移库单(一步) 明细字段——增加“可销数量”字段. 然后修改明细字段的“商品编号”自定义查询方案. 增加自定义资料检索方案hwyksp SQL: select ...
- php从命令行中接收参数
php一直都是作为服务器编程的主要角色,其实php也可已做脚本,比如从命令行中接收一些参数,下面就简单介绍一下如何从命令行中接收参数 代码如下: <?php var_dump($argv); ? ...
- Elasticsearch 5.0 _source field的简单认识
前言:本文的目的是为后续磁盘空间利用优化做铺垫,主要知识点来源于官网 一._source是什么 _source field是我们在PUT数据时候的json body: PUT store_index/ ...