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;
}
博客围绕n只松鼠在m棵栗子树下获取栗子展开。每棵树有首次落栗时间和间隔时间,松鼠需获取不少于k个栗子以避风暴。给出了计算最短时间的请求、输入输出格式、示例及限制条件,旨在解决松鼠获取足够栗子的最短时间问题。
1799

被折叠的 条评论
为什么被折叠?



