二分。

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

#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;
}

转载于:https://www.cnblogs.com/zufezzt/p/5899578.html

CodeForces 670D Magic Powder相关推荐

  1. codeforces 670D1 Magic Powder - 1

    题目链接:http://codeforces.com/problemset/problem/670/D1 题目:Magic Powder - 1 time limit per test 1 secon ...

  2. CodeForces 670D2 Magic Powder - 2

    Description The term of this problem is the same as the previous one, the only exception - increased ...

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

    http://codeforces.com/contest/670/problem/D2 简单的二分,二分所有可以做的饼干数,然后遍历就可以啦 #include <iostream> #i ...

  4. 【CodeForces - 670D1 】Magic Powder - 1 (模拟 或 枚举 或二分优化)

    题干: This problem is given in two versions that differ only by constraints. If you can solve this pro ...

  5. Magic Powder - 2

    https://codeforces.com/contest/670/problem/D2 The term of this problem is the same as the previous o ...

  6. Magic Powder - 2 (CF 670_D)

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

  7. codeforce之Magic Powder

    题目: The term of this problem is the same as the previous one, the only exception - increased restric ...

  8. Magic Powder - 1,2

    问题 This problem is given in two versions that differ only by constraints. If you can solve this prob ...

  9. Magic Powder - 2 CodeForces - 670D2(二分答案)

    先贴一篇关于二分边界问题的博客,看来自己还是对二分边界的理解不够深入 题目:今天我们要来造房子.造这个房子需要n种原料,每造一个房子需要第i种原料ai个.现在你有第i种原料bi个.此外,你还有一种特殊 ...

最新文章

  1. 如何使用Java中的UTC或GMT获取当前日期和时间?
  2. python字符串find函数-python常见字符串处理函数与用法汇总
  3. kib,mib和mb,kb的区别
  4. 1077篇!ICCV2019接收结果公布,你中了吗?(附7篇论文链接,含Oral)
  5. 内附PPT下载 | 阿里云资深技术专家 陈长城:一站式数据管理DMS及最新解决方案解读
  6. File类判断和获取功能
  7. 解决 IntelliJ IDEA 安装后界面消失,再次打开后界面不动
  8. 315曝光不良奸商 对企业不能罚酒三杯
  9. e盘是否具有读写权限_轻松搭建MySQL主从复制、读写分离(双机热备)
  10. 2021-07-07IF神经元模型
  11. centos6.2安装jdk7
  12. NLP︱高级词向量表达(二)——FastText(简述、学习笔记)
  13. mapbox 加载json数据 和数据中颜色 和高度 并根据数值加载颜色
  14. DBC2000是什么?DBC2000数据库文件超详细讲解
  15. 将html页面转成word(亲测可用)
  16. 华为网络篇 华为路由器的初始化配置-05
  17. 数据分析三大神器之一:Numpy
  18. 网络(韩志刚版笔记)
  19. 写给自己——瞎写瞎画坑规(自己挖坑自己填啊!!)
  20. MIT Technology Review 2022年“全球十大突破性技术”解读

热门文章

  1. 5月11日云栖精选夜读丨清华大学成功卫冕ASC18世界超算总决赛冠军,黑马上海科大斩获AI大奖
  2. 旅游消费券发放,驴妈妈造福旅游爱好者
  3. 小说阅读器 免费源码 高颜值 功能齐全
  4. SDIO_WiFi驱动学习之SDIO架构介绍及源码分析
  5. 社群经济与组织社群化 (2)
  6. 58 mysql 军规_58 到家 MySQL 军规升级版
  7. 常用flash引擎和框架
  8. 利用IDL输出影像快视图、拇指图
  9. Error:Flash Download failed - Could not load file ****.axf
  10. 信息技术用计算机绘画,童心笔下挥洒的那份真——信息技术组电脑绘画成果