1014 - Absolute Defeat
DESCRIPTION
Eric has an array of integers
a
1
,
a
2
,
.
.
.
,
a
n
a1,a2,…,an. Every time, he can choose a contiguous subsequence of length
k
k and increase every integer in the contiguous subsequence by
1
1.
He wants the minimum value of the array is at least
m
m. Help him find the minimum number of operations needed.
INPUT
There are multiple test cases. The first line of input contains an integer
T
T, indicating the number of test cases. For each test case:
The first line contains three integers
n
n,
m
m and
k
k
(
1
≤
n
≤
10
5
,
1
≤
k
≤
n
,
1
≤
m
≤
10
4
)
(1≤n≤105,1≤k≤n,1≤m≤104).
The second line contains
n
n integers
a
1
,
a
2
,
.
.
.
,
a
n
a1,a2,…,an
(
1
≤
a
i
≤
10
4
)
(1≤ai≤104).
OUTPUT
For each test case, output an integer denoting the minimum number of operations needed.
SAMPLE INPUT
3
2 2 2
1 1
5 1 4
1 2 3 4 5
4 10 3
1 2 3 4
SAMPLE OUTPUT
1
0
15
SOLUTION
“玲珑杯”ACM比赛 Round #1
#include<cstdio>
int pa[100011];
int main()
{
int n,m,k,T,i,j,ans,kl;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&m,&k);
for(i = 1; i <= n; i++)
scanf("%d",&pa[i]);
ans = 0;
for(i = 1; i <= n; i++)
{
if(pa[i] < m)
{
kl = m - pa[i];
for(j = i ; j < i + k && j <= n; j++)
pa[j] += kl;
ans += kl;
}
}
printf("%d\n",ans);
}
return 0;
}