“玲珑杯”ACM比赛 Round #1

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 (1n105,1kn,1m104)(1≤n≤105,1≤k≤n,1≤m≤104). The second line contains nn integers a1,a2,...,ana1,a2,...,an (1ai104)(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[1000000+10];
int main()
{
    int t,n,m,k;
    cin>>t;
    while(t--)
    {
        cin>>n>>m>>k;
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        int ans=0;
        int tmp;
        for(int i=0;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 0;
}
View Code

 

全部评论

相关推荐

昨天 10:10
已编辑
门头沟学院 人工智能
写这篇之前我犹豫了挺久。一方面是怕被人骂,&quot;又一个收割焦虑的转行帖&quot;;另一方面是看了太多用&nbsp;GPT&nbsp;套娃出来的「学习路线」文章,AI&nbsp;味重得让人没法读完。所以这篇全是亲身踩过的坑,时间线、用过的项目、当时的心路全都尽量原样写出来。如果你是大学生在迷茫要不要转&nbsp;AI,或者已经在转的路上,希望能给点参考。&nbsp;一个反共识的开场:你以为进&nbsp;OpenAI&nbsp;的人都是博士?&nbsp;先讲个故事,跟我没关系,但跟所有想转&nbsp;AI&nbsp;的人都有关系。&nbsp;OpenAI&nbsp;的&nbsp;Sora&nbsp;团队(就是搞文生视频那个)一共&nbsp;13&nbsp;个人。这里面有两个人特别有意思:&nbsp;Will&nbsp;DePue,密歇根大学计算机系,直接辍学了。17...
_hengheng:我也本,也算是做ai相关,我最开始感觉做ai工程师有多么多么困难,后来发现懂了原理后整体训练完全可以看成一个流程化的内容,开源方案太多了,大多基本都是按着模子在自家业务上做各种操作,就算是大厂的小部门也没那么多资源去训基模,反而更多的是像怎么把技术往业务方向靠近了,不过当前时代如果本科学历没那么好加上自己执行力不是特别强还真不建议走ai工程师这条路,可以试试其他ai的偏业务方向,不然校招不太好杀出来
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务