【1014 - Absolute Defeat】

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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值