D - Squirrel and chestnut
There are n squirrel(s) waiting below the feet of m chestnut tree(s). The first chestnut of the i-th tree will fall right after Ti second(s), and one more every Pi second(s) after that. The “big mama” of squirrels wants them to bring their nest no less than k chestnuts to avoid the big storm coming, as fast as possible! So they are discussing to wait below which trees to take enough chestnuts in the shortest time. Time to move to the positions is zero, and the squirrels move nowhere after that.

Request

Calculate the shortest time (how many seconds more) the squirrels can take enough chestnuts.
Input

The first line contains an integer t, the number of test cases, for each:
The first line contains the integers m,n,k, respectively.
The second line contains the integers Ti (i=1..m), respectively.
The third line contains the integers Pi (i=1..m), respectively.
(Each integer on a same line is separated by at least one space character, there is no added line between test cases)
Output

For each test cases, output in a single line an integer which is the shortest time calculated.

Example

Input:
2
3 2 5
5 1 2
1 2 1
3 2 5
5 1 2
1 1 1
Output:
4
3
* Explain (case #1): 2 squirrels waiting below the trees 2 and 3.

Limitations

0

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#define INF 0x3f3f3f3f
#define MAX 99999
using namespace std;
long long int a[MAX], b[MAX];
long long int c[MAX];
int n, m, k;
long long int maxm(long long int a, long long int b)//比较大小
{return a>b?a:b;
}
long long int cmp(long long int a, long long int b)
{return a>b;
}
int check(long long int mid)//看看在mid的时间,能不能满足要求
{for(int i=0;i<m;i++){if(mid<a[i])c[i] = 0;//此时没有果子else{c[i] = maxm(0, (mid-a[i]+b[i])/b[i]);//此时,果子数目}}sort(c, c+m, cmp);//按照果子数目由多到少排序long long int ans = 0;for(int i=0;i<min(n, m);i++)//现在最多可以得到多少的果子{ans += c[i];if(ans>=k)//满足要求,返回1return 1;}return 0;
}
int main()
{int T;scanf("%d", &T);while(T--){scanf("%d %d %d", &m, &n, &k);for(int i=0;i<m;i++)scanf("%lld", a+i);for(int i=0;i<m;i++)scanf("%lld", b+i);long long int l = 1;long long int r = MAX;long long int s = -1;while(l<=r)//对时间进行二分{long long int mid = (l + r) / 2;if(check(mid)){r = mid - 1;s = mid;}elsel = mid + 1;}printf("%lld\n", s);//输出合适的时间}return 0;
}

D - Squirrel and chestnut(二分)相关推荐

  1. CodeChef Squirrel and chestnut 题解

    原题链接:Squirrel and chestnut 题意:有\(n\)只松鼠在\(m\)棵树下,每一棵树会在\(t_i\)的时间掉下一颗果子,随后每隔\(p_i\)的时间会再落下一颗,现在\(n\) ...

  2. Squirrel and chestnut CodeChef - SQUIRREL

    There are n squirrel(s) waiting below the feet of m chestnut tree(s). The first chestnut of the i-th ...

  3. 算法图解/二分查找/简单查找/选择排序/递归算法/快速排序算法/

    大 O 表示法 大 O 表示法在讨论运行时间时,log 指的都是 log2 大 O 表示法指出了算法有多快,让你能够比较操作数,它指出了算法运行时间的增速,而并非以秒为单位的速度. 大 O 表示法指出 ...

  4. 分治算法的设计思想(二分检索、二分归并排序)

    分治策略思想: 将原问题划分或者归结为规模较小的子问题. 递归或迭代求解每一个问题. 将子问题的解综合得到原问题的解. 性质: 子问题与原问题具有相同的性质. 子问题的求解彼此独立. 划分时子问题的规 ...

  5. LeetCode简单题之二分查找

    题目 给定一个 n 个元素有序的(升序)整型数组 nums 和一个目标值 target ,写一个函数搜索 nums 中的 target,如果目标值存在返回下标,否则返回 -1. 示例 1: 输入: n ...

  6. 二分查找模板全面总结

    二分查找 二分法的引入 情形1 1.X的平方根 2.搜索旋转排序数组 情形2 1.第一个错误的版本 2.寻找峰值 3.寻找旋转排序数组中的最小值 情形3 在排序数组中查找第一个和最后一个位置 当遇到查 ...

  7. [C] [二分] C语言实现快速排序

    为了以防万一有人想不开想手撕快排呢?比如我. 通过快排来理解二分思想 什么是快排? 快排的思想不难,理解好递归很重要. 什么是递归? 递归,就是在运行的过程中调用自己. 构成递归需具备的条件: 子问题 ...

  8. Showstopper [POJ3484] [二分] [思维]

    Description 给你n个数列,问哪一个数字在所有的数列中出现了奇数次(最多一个). Sample Input 1 10 1 2 10 11 10 1 1 10 11 10 1 4 4 1 1 ...

  9. BZOJ3166 [Heoi2013]Alo 【可持久化trie树 + 二分 + ST表】

    题目 Welcome to ALO ( Arithmetic and Logistic Online).这是一个VR MMORPG , 如名字所见,到处充满了数学的谜题. 现在你拥有n颗宝石,每颗宝石 ...

最新文章

  1. 让asp.net默认的上传组件支持进度条反映(转)
  2. 使用 Github Pages 发布你的项目文档
  3. 《软件需求》读后感03
  4. 高度平衡的二叉搜索树基础概念与经典题目(Leetcode题解-Python语言)
  5. 单身狗有福了!斯坦福教授化身丘比特,AI算法之箭帮你配真命爱侣
  6. XML DOM 节点类型(Node Types)
  7. 贴片晶振脚位_贴片晶振的焊接方法和注意事项
  8. python3、ipython3、setup-tools、pip等环境搭建详细总结
  9. logstash 获取多个kafka_日志工程Logstash日志采集入门篇
  10. lammps教程:单原子应力计算及应力云图绘制方法
  11. 三运放差分放大电路分析_运放19——三运放仪表放大器工作原理分析
  12. pytorch和python的区别_Keras和PyTorch的视觉识别与迁移学习对比
  13. 运行 CTS 测试命令
  14. 面试 增删改查用的java知识,工作3年的程序员,面试还说自己只会增删改查?这些高频面试题还不看起来!...
  15. pandas如何将两个表根据某个数组合并
  16. 为什么99%的价值投资者最后都会死去?
  17. 【深入理解JS核心技术】2. 什么是原型链?
  18. jquery设置checkbox选中和未选中的方式
  19. 网易云音乐机器学习平台实践
  20. 计算机单考单招高考考纲,2020年单独招生考试大纲

热门文章

  1. 山西省大学计算机专业排名,山西省:排名前14的大学!山西的大学分为5档,前2档最难考!...
  2. LiveNVR监控流媒体Onvif/RTSP功能支持海康摄像头通过海康SDK接入支持回看倍速播放海康设备存储的设备录像
  3. Things_androidThings入门
  4. 两个向量夹角的cos值
  5. 华为智能汽车产业研究与投资机会分析
  6. 我的架构梦:(二)MyBatis的一级、二级、分布式缓存的应用以及源码分析
  7. 单机版Docker Swarm安装及试用
  8. 毛线剪藏(MaoXian Web Clipper)的安装、设置和使用
  9. Python全国二级等级考试(2019)
  10. 恶人自有天收:如何能使僵尸网络Mirai的服务器宕机