zoukankan      html  css  js  c++  java
  • 玲珑学院-ACM比赛1014

    1014 - Absolute Defeat

    Time Limit:2s Memory Limit:64MByte

    Submissions:257Solved:73

    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
    32 2 21 15 1 41 2 3 4 54 10 31 2 3 4
    SAMPLE OUTPUT

    1015


    源代码:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<stack>
    #include<queue>
    #include<vector>
    #include<deque>
    #include<map>
    #include<set>
    #include<algorithm>
    #include<string>
    #include<iomanip>
    #include<cstdlib>
    #include<cmath>
    #include<sstream>
    #include<ctime>
    using namespace std;
    
    typedef long long ll;
    int ans[200005];
    
    int main()
    {
        int t;
        int n,m,k;
        int temp;
        ll sum;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d%d%d",&n,&m,&k);
            sum = 0;
            memset(ans,0x3f3f3f3f,sizeof(ans));
            for(int i = 0; i < n; i++)
                scanf("%d",&ans[i]);
            for(int i = 0; i < n; i++)
            {
                if(ans[i]<m)
                {
                    temp=m-ans[i];
                    sum+=temp;
                    for(int j = i; j < i+k;j++)
                        ans[j]+=temp;
                }
            }
            printf("%lld
    ",sum);
        }
    	return 0;
    }


  • 相关阅读:
    嵌入式工程师C语言面试常见的0x10个问题
    C语言初学者网站推荐
    strlen和sizeof
    基于Docker搭建GitLab和Maven私服
    linux暴露端口可以被外部访问
    MySQL新增用户及赋予权限
    Docker添加域名解析
    Netstat 网络命令详解
    Mysql索引太长导致同步数据结构失败解决方法
    完美解决Cannot download "https://github.com/sass/node-sass/releases/download/binding.nod的问题
  • 原文地址:https://www.cnblogs.com/lemonbiscuit/p/7776092.html
Copyright © 2011-2022 走看看