Start Time:2016-08-20 13:00:00 End Time:2016-08-20 18:00:00 Refresh Time:2017-11-12 19:51:52 Public

A -- Absolute Defeat

Time Limit:2s Memory Limit:64MByte

Submissions:394Solved:119

DESCRIPTION

Eric has an array of integers 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
There are multiple test cases. The first line of input contains an integer 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
SOLUTION
 
【题意】:给你一个长度为n的序列,每次你只能选择连续的k个数字加1,问你要进行多少次操作才能使所有的a[i]都大于m。 
【分析】:直接枚举,看每个数是否>m,否的话给从它开始的k个数,每个数都加上m-a[i]。
【代码】:

#include <bits/stdc++.h>

using namespace std;
int a[+];
int main()
{
int t,n,m,k;
cin>>t;
while(t--)
{
cin>>n>>m>>k;
for(int i=;i<n;i++)
{
cin>>a[i];
}
int ans=;
int tmp;
for(int i=;i<n;i++)
{
if(a[i]<m)
{
tmp=m-a[i];
ans+=tmp;
for(int j=i;j<i+k;j++) //连续长度k内元素都加上差值
{
a[j]+=tmp;
}
}
}
printf("%d\n",ans);
}
return ;
}

最新文章

  1. xhprof安装使用
  2. JAVA作业)01
  3. springMVC的两种下载方式
  4. AngularJs应用页面切换优化方案(转)
  5. Python积木之with
  6. Unity3D ShaderLab 立方体图的反射遮罩
  7. IDirect3DDevice9::Clear
  8. Android 实现在线程中联网
  9. C++ Builder中TOpenDialog控件的使用例子
  10. Hadoop(五)搭建Hadoop与Java访问HDFS集群
  11. 装 ubuntu + win10 出现 grub rescue 并处理之
  12. 为什么text的值改变后onchange没有反应?
  13. iOS UI基础-7.0 UIScrollView
  14. Educational Codeforces Round 61 D 二分 + 线段树
  15. oracle用户密码过期!the password has expired
  16. lazarus汉化
  17. cognos report上钻下钻报表处理方法(2)
  18. [Jobdu] 题目1516:调整数组顺序使奇数位于偶数前面
  19. Runtime 应用(一)拦截系统自带的方法交换实现
  20. Python: 分数运算

热门文章

  1. 剑指Offer - 九度1370 - 数组中出现次数超过一半的数字
  2. 【Invert Binary Tree】cpp
  3. 1.0 python-client以及ui自动化介绍
  4. 一个符号冲突导致的core分析
  5. Elasticsearch同义词词汇单元过滤器
  6. Python编码报错
  7. HDU 4758 Walk Through Squares( AC自动机 + 状态压缩DP )
  8. 如何出发匿名映射呀【log】
  9. [zoj] 1081 Points Within || 判断点是否在多边形内
  10. 用hibernate.properties代替hibernate.cfg.xml配置常用的属性