0
点赞
收藏
分享

微信扫一扫

玲珑学院-1014-Absolute Defeat【思维】

_karen 2022-08-24 阅读 27


题目链接:​​点击打开链接​​


1014 - Absolute Defeat



Time Limit:2s Memory Limit:64MByte

Solved:76


DESCRIPTION



a1,a2,...,ana1,a2,...,an. Every time, he can choose a contiguous subsequence of length kk and increase every integer in the contiguous subsequence by 11.He wants the minimum value of the array is at least mm. Help him find the minimum number of operations needed.


INPUT



TT, indicating the number of test cases. For each test case:The first line contains three integers nn, mm and kk (1≤n≤105,1≤k≤n,1≤m≤104)(1≤n≤105,1≤k≤n,1≤m≤104).The second line contains nn integers a1,a2,...,ana1,a2,...,an (1≤ai≤104)(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


题意:给你一个长度为 n 的序列,然后你每次只能处理长度为 k 子序列,每次处理使这长度为 k 的子序列每个值加 1,问最少要处理几次才能使整个序列的每个元素都大于 m

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int MAX=1e5+10;
int n,m,k;
int a[2*MAX];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d %d %d",&n,&m,&k);
memset(a,0,sizeof(a));
int x,ans=0;
for(int i=1;i<=n;i++)
{
scanf("%d",&x);
a[i]+=a[i-1];
if(x+a[i]<m) // 每次的 a[i]只有两个值要么是 n*k,要么是 0
{
int step=m-a[i]-x;
ans+=step;
a[i]+=step;
a[i+k]-=step; // 每次处理的长度只有 k,而上面还有个累加,所以这里先把第 i+k位减 step,
} // 这样就保证了上面判断的 a[i],只可能是 两种值
}
printf("%d\n",ans);
}
return 0;
}



举报

相关推荐

0 条评论