简单题,线性遍历一遍就好。但要注意如果ave(p)计算到第i个顾客为止,那么第i+1个顾客来到时必须睡着。
#include <stdio.h>
#include <memory.h>
int c[1001];
int sum[1001];
int T, n, p, t;
int i, tmin, w;
int main()
{
double max, temp;
scanf("%d", &T);
while(T --)
{
scanf("%d", &n);
memset(sum, 0, sizeof(sum));
for(i=1; i<=n; ++i)
{
scanf("%d", &p);
sum[i] = p + sum[i-1];
}
for(i=1; i<=n; ++i)
scanf("%d", c+i);
max = 0, tmin = 0;
for(i=1; i<=n; ++i)
{
t = c[i] - c[i-1];
if(t > tmin) tmin = t;
temp = 1.0*sum[i]/i;
if(i==n && temp>max)
{
max = temp;
w = tmin;
}
else if(temp > max)
{
if(c[i+1]-c[i] > tmin)
{
max = temp;
w = tmin;
}
}
}
printf("%.6lf %.6lf\n", 1.0*w, max);
}
return 0;
}