当前位置:网站首页>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();
}
边栏推荐
- 一致性哈希的简单认识
- How mysterious is "PIP not an internal or external command, nor a runnable program or batch file"
- [games101] class note 8 - shading (shading frequency, graphics pipeline, texture mapping)
- Explain
- Login to MySQL
- How do indexes match?
- When will the index fail
- Ctfshow-web265 (deserialization)
- Wechat applet notes
- Theory + practice will help you master the dynamic programming method
猜你喜欢

Design rule check constraint (set_max_transition, set_max_capability)

I learned database at station B (10): View

Unsupported class file major version 60

Using / developing private plug-ins in traifik proxy 2.5 (traifik official blog)

设计规则检查约束(set_max_transition、set_max_capacitance)

逐向双碳:东数西算中的绿色需求与竞争焦点

Wechat applet notes

What is the difference between union and union all

EditText控制从左上角开始

Installation and testing of open source deep learning framework plaidml
随机推荐
PostgreSQL数据库复制——后台一等公民进程WalReceiver pg_stat_wal_receiver视图
代理与反射
Detailed explanation of search tree and hash table
Alipay payment episode 11: monitoring after successful payment callback
新来的同事问我 where 1=1 是什么意思???
Microsoft Word tutorial, how to insert page numbers and table of contents in word?
6 R factor and judgment Na
EditText控制从左上角开始
The difference between MySQL full table scanning and indexing
用户权限和组权限
标量、向量、数组和矩阵
Demand and business model innovation - demand 2- demand basis
Design rule check constraint (set_max_transition, set_max_capability)
可测性设计学习笔记
Microsoft Word tutorial, how to insert a header or footer in word?
System log
system()
unable to recognize “*.yaml“: no matches for kind “ClusterRole“ in version “rbac.authoriz
Index optimization principle
Proxy and reflection