当前位置:网站首页>A Zhu and Xu Baobao's high-rise game - difference
A Zhu and Xu Baobao's high-rise game - difference
2022-06-12 20:20:00 【Wawa source】


#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
#define int long long
#define x first
#define y second
const int N = 100010;
int h[N];
void solve()
{
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)cin>>h[i];
for(int i=n;i>=1;i--)h[i]-=h[i-1];
int res=0;
for(int i=n;i-m>0;i--)
if(h[i]>0)
res+=h[i],h[i-m]+=h[i],h[i]=0;
for(int i=2;i+m-1<=n;i++)
if(h[i]<0)res-=h[i],h[i+m]+=h[i],h[i]=0;
for(int i=2;i<=n;i++)
if(h[i])
res=-1;
cout<<res<<'\n';
}
signed main()
{
int T;cin>>T;
while(T--)solve();
}
边栏推荐
- Lightroom 大使系列:用 Meg Loeks 捕捉怀旧之情
- BigTable (II): how BigTable achieves scalability and high performance
- MySQL Basics
- 进程的创建fork()、消亡wait()
- [live streaming] understand the design of d3js and learn how to read the source code.
- 3 R complex data types
- Niuke.com: sum of three numbers
- The Milvus graphical management tool Attu is coming!
- Niuke net: somme des trois nombres
- Kyma application connectivity feature introduction
猜你喜欢

WordPress station group tutorial automatic collection of pseudo original release tutorial

How to close icloud when Apple ID of Apple mobile phone forgets password and frequently jumps out to log in

In 2022, FISCO bcos MVP recognized that the channel was open and invited you to become an open source leader

Explain

Demand and business model innovation - demand 3- demand engineering process

Alipay payment episode 11: monitoring after successful payment callback

Design rule check constraint (set_max_transition, set_max_capability)

Microsoft Word 教程,如何在 Word 中插入页码、目录?

EditText控制从左上角开始

The Milvus graphical management tool Attu is coming!
随机推荐
MySQL Basics
[leetcode 7 solution] integer inversion
Solve NPM compilation times node_ modules/optipng-bin/vendor/optipng ENOENT
Demand and business model innovation - demand 3- demand engineering process
检测当前系统语言
Using / developing private plug-ins in traifik proxy 2.5 (traifik official blog)
Golden, silver and four job hopping season, teach you these tips to improve the interview success rate
When will the index fail
House raiding 3
3 R complex data types
Operating instructions for installing mysql5.7 in centos7
Detailed explanation of SQL exists usage
Axure RP 9 for MAC (interactive product prototyping tool) Chinese version
使用Swagger生成 API 文档(go语言示例)
Index optimization principle
centos7 安装 mysql 5.7
MySQL - the execution order of an SQL statement
Deep feature synthesis and genetic feature generation, comparison of two automatic feature generation strategies
How to make a computer installation and startup USB flash disk
Analysis of test questions in Chapter 13 of PMP preparation