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 ;
}

“玲珑杯”ACM比赛 Round #1的更多相关文章

  1. “玲珑杯”ACM比赛 Round #12题解&源码

    我能说我比较傻么!就只能做一道签到题,没办法,我就先写下A题的题解&源码吧,日后补上剩余题的题解&源码吧!                                     A ...

  2. “玲珑杯”ACM比赛 Round #19题解&源码【A,规律,B,二分,C,牛顿迭代法,D,平衡树,E,概率dp】

    A -- simple math problem Time Limit:2s Memory Limit:128MByte Submissions:1599Solved:270 SAMPLE INPUT ...

  3. “玲珑杯”ACM比赛 Round #19 B -- Buildings (RMQ + 二分)

    “玲珑杯”ACM比赛 Round #19 Start Time:2017-07-29 14:00:00 End Time:2017-07-29 16:30:00 Refresh Time:2017-0 ...

  4. “玲珑杯”ACM比赛 Round #18

    “玲珑杯”ACM比赛 Round #18 Start Time:2017-07-15 12:00:00 End Time:2017-07-15 15:46:00 A -- 计算几何你瞎暴力 Time ...

  5. “玲珑杯”ACM比赛 Round #1 题解

    A:DESCRIPTION Eric has an array of integers a1,a2,...,ana1,a2,...,an. Every time, he can choose a co ...

  6. 玲珑杯”ACM比赛 Round #4 1054 - String cut 暴力。学到了扫描的另一种思想

    http://www.ifrog.cc/acm/problem/1054 问删除一个字符后的最小循环节是多少. 比赛的时候想不出,不知道怎么暴力. 赛后看了别人代码才晓得.唉,还以为自己字符串还不错, ...

  7. “玲珑杯”ACM比赛 Round #18--最后你还是AK了(搜索+思维)

    题目链接   DESCRIPTION INPUT OUTPUT SAMPLE INPUT 1 4 2 1 2 5 2 3 5 3 4 5 5 5 SAMPLE OUTPUT 35 HINT 对于样例, ...

  8. “玲珑杯”ACM比赛 Round #22 E 贪心,脑洞

    1171 - 这个E大概是垃圾桶捡来的 Time Limit:2s Memory Limit:128MByte Submissions:138Solved:45 DESCRIPTION B君在做 CO ...

  9. “玲珑杯”ACM比赛 Round #13 题解&源码

    A 题目链接:http://www.ifrog.cc/acm/problem/1111 分析:容易发现本题就是排序不等式, 将A数组与B数组分别排序之后, 答案即N∑i=1Ai×Bi 此题有坑,反正据 ...

随机推荐

  1. 【Luogu P2257】YY 的 GCD

    题目 求: \[ \sum_{i = 1}^n \sum_{j = 1}^m [\gcd(i, j) \in \mathbb P] \] 有 \(T\) 组数据, \(T\le 10^4, n, m\ ...

  2. 抓包工具 - Fiddler - (一)

    <转载于 miantest> Fiddler基础知识 Fiddler是强大的抓包工具,它的原理是以web代理服务器的形式进行工作的,使用的代理地址是:127.0.0.1,端口默认为8888 ...

  3. springboot示例参考网站

    https://blog.csdn.net/u013248535/article/details/55100979/

  4. Djano之写api使用django_rest_framework【海瑞博客】

    使用django rest framework 可以更快速和友好的编写api,当然网上有很多教程,对于高手来说相对很简单,对于新手来说,根本搞不明白.那是你没有搞明白你自己的职责,做为后端,我们只要提 ...

  5. time模块与random模块,六位含字母随机验证码

    # time模块# import time# time.time()#计算这一时刻时间戳 *******# time.sleep(1)#让cpu休眠一定时间 *******# time.clock() ...

  6. python学习总结----时间模块 and 虚拟环境(了解)

    time - sleep:休眠指定的秒数(可以是小数) - time:获取时间戳 # 获取时间戳(从1970-01-01 00:00:00到此刻的秒数) t = time.time() print(t ...

  7. 剑指offer-替换空格02

    题目描述 请实现一个函数,将一个字符串中的每个空格替换成“%20”.例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy. class Solution: ...

  8. bayes学习笔记

    贝叶斯(BAYES)判别思想是根据先验概率求出后验概率,并依据后验概率分布作出统计推断.所谓先验概率,就是用概率来描述人们事先对所研究的对象的认识的程度:所谓后验概率,就是根据具体资料.先验概率.特定 ...

  9. 聊聊、Spring ServletContainerInitializer

    我们平时用 Java 注解很多,例如 @Configuration.@Component.@Service,我们习惯于通过 XML 方式来实现 Web,而用 Java 注解方式来实现 Web 却很少. ...

  10. Codeforces Round #328(Div2)

    CodeForces 592A 题意:在8*8棋盘里,有黑白棋,F1选手(W棋往上-->最后至目标点:第1行)先走,F2选手(B棋往下-->最后至目标点:第8行)其次.棋子数不一定相等,F ...