UESTC 1817 Complete Building the Houses 贪心

简介:

同是比赛时候的一道水题,比赛的时候以为满层的就不能继续建了,没想到可以忽视它……

搞清题意后,唯一要注意的一点就是ans是long long的


/*
author:jxy
lang:C/C++
university:China,Xidian University
**If you need to reprint,please indicate the source**
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#define INF 1E9
using namespace std;
int a[1000001];
long long ans=0;
int main()
{
    int now;
    int T,C=0;
    int n,m,i,t;
    scanf("%d",&T);
    while(T--)
    {
        ans=now=0;
        scanf("%d%d",&n,&m);
        for(i=0;i<n;i++)
        {
            scanf("%d",&t);
            if(now>=t)
                a[i]=0;
            else
            {
                a[i]=t-now;
                ans+=a[i];
                now=t;
            }
            if(i+1-m>=0)//超过m长度
                now-=a[i+1-m];
        }
        printf("Case #%d: %lld\n",++C,ans);
    }
}


目录
相关文章
|
8月前
|
PHP
configure: error: Package requirements (libzip >= 0.11 libzip ≠ 1.3.1 libzip ≠ 1.7.0) were not met
configure: error: Package requirements (libzip >= 0.11 libzip ≠ 1.3.1 libzip ≠ 1.7.0) were not met
139 0
configure: error: Package requirements (libzip >= 0.11 libzip ≠ 1.3.1 libzip ≠ 1.7.0) were not met
PAT (Advanced Level) Practice 1044 Shopping in Mars (前缀和 二分)
PAT (Advanced Level) Practice 1044 Shopping in Mars (前缀和 二分)
67 0
|
存储
PAT (Advanced Level) Practice 1011 World Cup Betting (20 分)
PAT (Advanced Level) Practice 1011 World Cup Betting (20 分)
55 0
|
存储 算法
PAT (Advanced Level) Practice 1046 Shortest Distance (20 分)
PAT (Advanced Level) Practice 1046 Shortest Distance (20 分)
73 0
PAT (Advanced Level) Practice 1046 Shortest Distance (20 分)
PAT (Advanced Level) Practice - 1004 Counting Leaves(30 分)
PAT (Advanced Level) Practice - 1004 Counting Leaves(30 分)
87 0
PAT (Advanced Level) Practice - 1049 Counting Ones(30 分)
PAT (Advanced Level) Practice - 1049 Counting Ones(30 分)
94 0
PAT (Advanced Level) Practice - 1096 Consecutive Factors(20 分)
PAT (Advanced Level) Practice - 1096 Consecutive Factors(20 分)
114 0
PAT (Advanced Level) Practice - 1122 Hamiltonian Cycle(25 分)
PAT (Advanced Level) Practice - 1122 Hamiltonian Cycle(25 分)
93 0
PAT (Advanced Level) Practice - 1068 Find More Coins(30 分)
PAT (Advanced Level) Practice - 1068 Find More Coins(30 分)
92 0
PAT (Advanced Level) Practice - 1087 All Roads Lead to Rome(30 分)
PAT (Advanced Level) Practice - 1087 All Roads Lead to Rome(30 分)
76 0