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 Pisecond(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<t≤20
  • 0<m,n≤10,000
  • 0<k≤107
  • 0<Ti,Pi≤100
#include <bits/stdc++.h>
using namespace std;
int T[10005];
int P[10005];
int num[10005];
int k,m,n;
bool cmp(int a,int b)
{return a>b;
}
int ok(int t)
{int i,j;int sum = 0;for(i=1;i<=m;i++){if(T[i] > t){num[i] = 0;continue;}num[i] = (t-T[i])/P[i]+1;if(num[i] > k) return 1;}sort(num+1,num+1+m,cmp);sum = 0;for(i=1;i<=n&&i<=m;i++){sum += num[i];if(sum >= k) return 1;}return 0;}int main()
{int t,i,j;scanf("%d",&t);while(t--){scanf("%d%d%d",&m,&n,&k);for(i=1;i<=m;i++){scanf("%d",&T[i]);}for(i=1;i<=m;i++){scanf("%d",&P[i]);}int l,r,mid;l = 0;r = 2e9;while(l+1>r){mid = (l+r)>>1;if(ok(m)) r = m;else l = m;}if(ok(l)) printf("%d \n",l);else printf("%d \n",r);}return 0;
}

Squirrel and chestnut CodeChef - SQUIRREL相关推荐

  1. CodeChef Squirrel and chestnut 题解

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

  2. D - Squirrel and chestnut(二分)

    D - Squirrel and chestnut There are n squirrel(s) waiting below the feet of m chestnut tree(s). The ...

  3. squirrel sql client linux,SQuirreL SQL Client

    SQuirreL SQL Client是一款功能强大的服务器配置管理软件,该软件能够帮助用户快速.高效的配置服务器,可以用来查看/编辑数据库的内容.发出SQL命令,完美兼容Windows系统和mac. ...

  4. squirrel sql mysql_无法使用SQuirreL连接到MySQL数据库

    我无法使用客户端Squirrel SQL连接到 MySQL.我之前设法连接到Oracle和Derby,但这一次,我不知道我做错了什么. 我在Mac上安装了MySQL,遵循以下步骤: >要安装My ...

  5. linux sql server客户端,Linux的MS SQL Server客户端SQuirrel SQL Client

    因为工作需要,要在ubuntu下连接mssql数据库,找了很久终于找到了SQuirreL SQL Client. SQuirreL SQL Client最大的魅力在于: 基于Java,具备良好的夸平台 ...

  6. wpf入门第七篇 使用Squirrel自动更新应用

    前言 本文是wpf入门系列第7篇,面向有winform或者web前端基础的.并且也有C#基础的同学. 本文简单的介绍了如何使用 Squirrel 来为 WPF 客户端 进行自动检查更新. Squirr ...

  7. 连接HiveServer2的图形化工具SQuirrel和Dbeaver

    文章目录 SQuirrel SQL Client简介 视频演示 安装SQuirrel SQL Client 启动hdfs和hiveserver2 配置SQuirrel SQL Client 使用SQu ...

  8. squirrel 脚本_Squirrel便携式Shell和脚本语言

    1799年,一位法国陆军工程师做出了惊人的发现. 不,不是鹅肝,卡门培尔奶酪,巴氏杀菌法或萨特法,而是罗斯塔石,这是解密埃及大部分古代象形文字的关键(参见图1). 图1. Rosetta石头,一种11 ...

  9. SQuirreL SQL Client的安装

    目录 安装 Squirrel 配置 Squirrel 使用 Squirrel 查询数据 安装 Squirrel 步骤 1: 下载 Squirrel http://squirrel-sql.source ...

最新文章

  1. 阿里云推荐码:8N6TBT
  2. FPGA配置模式(Altera版)
  3. Vivado使用误区与进阶——XDC约束技巧之I/O篇 (上)
  4. 百度新key申请步骤
  5. android view禁止右滑,ViewPager 禁止左右滑动完美解决
  6. php实现加密解密,php实现加密与解密的原理与用法
  7. HDU2086 A1 = ?【水题】
  8. springside4例子
  9. 静态网页-学校官网(附源码)
  10. CentOS7中Docker安装mysql主从复制、日常排错
  11. php soapfault 怎么用,SoapFault出现的问题及解决办法分享
  12. 浅析微信支付:公众平台卡券功能开通、HTML5线上发券(JS-SDK接口)、查看卡券详情
  13. 350套前端网站模板
  14. python中使用python-dotenv管理环境变量
  15. 运营商大数据的发展现状和趋势
  16. Java别踩白块外挂(附源码)
  17. bbpress 添加 featured image
  18. 2036:【例5.3】开关门
  19. Origin pro更改语言灰色时的解决办法
  20. 【NI Multisim 14.0 操作实例——音量控制电路】

热门文章

  1. Wework创始人再创业,靠美版“自如”估值10亿美金
  2. 问卷调查系统搭建(一)
  3. Windows_U盘_SD卡_硬盘等存储介质无法完成格式化
  4. 中国大学 科研水平 最新排行榜(ESI)
  5. 这家公司只有1个人,年赚一个亿
  6. 关于点进Steam页面白屏解决办法
  7. dell 1u服务器型号,戴尔_PowerEdge R240_1U机架式服务器_小型企业服务器选购 | Dell 中国大陆...
  8. unity urp内置lit材质源码解析(中)
  9. Ubuntu环境中英文切换
  10. Sputtr--万能搜索引擎