Magic Powder - 2
https://codeforces.com/contest/670/problem/D2
The term of this problem is the same as the previous one, the only exception — increased restrictions.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 109) — the number of ingredients and the number of grams of the magic powder.
The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ 109), where the i-th number is equal to the number of grams 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 will be able to bake using the ingredients that she has and the magic powder.
Examples
input
1 1000000000 1 1000000000
output
2000000000
input
10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 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
题意:同上一题,就是数开大了,得用二分 Hait: INF比较小,所以得用3000000000ll就行了
#include <iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
typedef long long ll ;
ll need[100008];
ll have[100008];
ll tmpp[100008];
ll n,k;
ll Slove(ll mid)
{ ll sum=k;for(ll i=1;i<=n;i++){tmpp[i]=have[i]-mid*need[i];if(tmpp[i]<0)sum+=tmpp[i];if(sum<0)return 0;}return 1;
}
int main()
{while(~scanf("%I64d%I64d",&n,&k)){for(ll i=1;i<=n;i++){scanf("%I64d",&need[i]);}for(ll i=1;i<=n;i++){scanf("%I64d",&have[i]);}ll ans=0;ll mid;ll l=0;ll r=3000000000ll;while(r>=l){mid=(l+r)/2;if(Slove(mid)==1){ans=mid;l=mid+1;}else{r=mid-1;}}printf("%I64d\n",ans);}//cout << "Hello world!" << endl;return 0;
}
Magic Powder - 2相关推荐
- 【CodeForces - 670D1 】Magic Powder - 1 (模拟 或 枚举 或二分优化)
题干: This problem is given in two versions that differ only by constraints. If you can solve this pro ...
- codeforce之Magic Powder
题目: The term of this problem is the same as the previous one, the only exception - increased restric ...
- Magic Powder - 1,2
问题 This problem is given in two versions that differ only by constraints. If you can solve this prob ...
- codeforces 670D1 Magic Powder - 1
题目链接:http://codeforces.com/problemset/problem/670/D1 题目:Magic Powder - 1 time limit per test 1 secon ...
- CodeForces 670D2 Magic Powder - 2
Description The term of this problem is the same as the previous one, the only exception - increased ...
- Magic Powder - 2 (CF 670_D)
http://codeforces.com/problemset/problem/670/D2 The term of this problem is the same as the previous ...
- E - Magic Powder - 2(二分查找)
该题数据量较大,根据题目答案最大2*10^9,可以通过二分法查找最大做的蛋糕数,用魔法素材把每个材料补充到二分的值需要的素材数,判断总共需要的素材数和k的大小关系进行二分 #include<io ...
- Magic Powder - 2 CodeForces - 670D2(二分答案)
先贴一篇关于二分边界问题的博客,看来自己还是对二分边界的理解不够深入 题目:今天我们要来造房子.造这个房子需要n种原料,每造一个房子需要第i种原料ai个.现在你有第i种原料bi个.此外,你还有一种特殊 ...
- CodeForces 670D2 Magic Powder - 2(二分+贪心)
http://codeforces.com/contest/670/problem/D2 简单的二分,二分所有可以做的饼干数,然后遍历就可以啦 #include <iostream> #i ...
最新文章
- 功能基因多样性研究概述
- java+jvm+log_java9 gc log参数迁移
- 如何扩展以太坊:分片
- 1xx、101、100 状态详解
- 初识Typescript及vscode环境配置
- ARC107——D - Number of Multisets
- 爬虫里的多线程基本使用
- python 数据写入json文件时中文显示Unicode编码问题
- 支持多分支语句吗_Go的条件判断语句
- 禁止特定IP访问Oracle数据库
- Redis: 配置文件示例
- 怎么使用 soapui 做接口测试?
- ubuntu 18.04 gnome shift键失灵
- matplotlib工具栏源码探析三(添加、删除自定义工具项)
- This Python interpreter is in a conda environment
- 一款免费的网络流量实时监控软件
- HDU6305: RMQ Similar Sequence 题解
- 3种可以拆分PDF文档页面的简单方法
- 视频AI边缘计算技术在安全生产监管中的场景化应用
- 关于IT行业如何提升英文水平
热门文章
- 计算机简单游戏有什么用,简单又好玩的互动游戏 简单又好玩的互动游戏有哪些...
- java 正则 空格_Java中关于空格的正则表达式
- html左边高140px怎么设置,html:侧边栏+滚动div,高度设置为当前页面大小
- php 正则 菜鸟,PHP正则表达式基础入门
- 为什么都用m3u8_为什么中国人都喜欢用红砖盖房?
- node sqlite 插入数据_使用 Sequelize 操作 Sqlite3 数据库
- 九十一、Python的GUI系列 | QT组件篇
- r语言的逻辑回归分类
- php订单系统 帝国cms,帝国CMS商城系统在线支付后,订单邮件提醒
- 微信小程序view标签内容 文本过长,自动换行的问题