正解:贪心

解题报告:

传送门$QwQ$

$umm$感觉这种问题还蛮经典的,,,就选了某个就不能选另一个这样儿,就可以用堆模拟反悔操作

举个$eg$,如果提出了$a_i$,那就$a_{i-1}$和$a_{i+1}$都不能选了,所以如果选了$a_i$之后想反悔选$a_{i-1}$和$a_{i+1}$就相当于只能另外获得$a_{i+1}+a_{i-1}-a_{i}$的收益了.所以每次取出堆顶$a_{i}$之后,就把$a_{i-1}$和$a_{i+1}$删了,然后插入$a_{i-1}+a_{i+1}-a_{i}$.然后多个数也差不多$QwQ$

所以就用个堆+链表维护下就成$QwQ$

$over$

#include<bits/stdc++.h>
using namespace std;
#define il inline
#define gc getchar()
#define ll long long
#define ri register int
#define rb register bool
#define rc register char
#define rp(i,x,y) for(ri i=x;i<=y;++i)
#define my(i,x,y) for(ri i=x;i>=y;--i)
#define lb(x) lower_bound(st+1,st+st_cnt+1,x)-st const int N=+,inf=1e9;
int n,K,a[N],l[N],r[N],d[N];
ll as;
bool vis[N];
struct node{ll dat;int id;}tmp;
priority_queue<node>Q; il int read()
{
rc ch=gc;ri x=;rb y=;
while(ch!='-' && (ch>'' || ch<''))ch=gc;
if(ch=='-')ch=gc,y=;
while(ch>='' && ch<='')x=(x<<)+(x<<)+(ch^''),ch=gc;
return y?x:-x;
}
il bool operator < (node gd,node gs){return gd.dat>gs.dat;} int main()
{
//freopen("3620.in","r",stdin);freopen("3620.out","w",stdout);
n=read();K=read();
rp(i,,n-){d[i]=read();if(i){tmp=(node){a[i]=d[i]-d[i-],i};Q.push(tmp);l[i]=i-;r[i]=i+;}}
r[]=;l[n]=n-;a[]=a[n]=inf;
while(K--)
{
while(vis[Q.top().id])Q.pop();
node nw=Q.top();Q.pop();ri pos=nw.id;
as+=nw.dat;nw.dat=a[pos]=a[l[pos]]+a[r[pos]]-a[pos];Q.push(nw);
vis[l[pos]]=vis[r[pos]]=;l[pos]=l[l[pos]];r[pos]=r[r[pos]];r[l[pos]]=pos;l[r[pos]]=pos;
}
printf("%lld\n",as);
return ;
}

最新文章

  1. Oracle SQL Developer 连接 MySQL
  2. 如何在mac本上安装android sdk 避免被墙
  3. SQLite 创建自增长标识列
  4. 【转】web测试总结
  5. 元素JS拖动的实现
  6. 关于String和StringBuffer的使用
  7. iOS开发核心语言Objective C —— 所有知识点总结
  8. JAVA开发环境 - 环境变量及配置
  9. 【HDOJ】4704 Sum
  10. Swift - AppDelegate.swift类中默认方法的介绍
  11. itmacy_我的博客
  12. Vue 爬坑之路(九)—— 用正确的姿势封装组件
  13. JQuery AJAX 全局设置
  14. Docker 系列七(Dubbo 微服务部署实践).
  15. BUG描述规范管理
  16. kafka definitive guide - reading notes
  17. MFC坐标转换
  18. PHP和JS中全局变量和局部变量
  19. (The application/json Media Type for JavaScript Object Notation (JSON))RFC4627-JSON格式定义
  20. hdu-4725-The Shortest Path in Nya Graph-层次网络

热门文章

  1. 快速完成智能数据构建,Dataphin公共云版本全面解读
  2. @loj - 2092@ 「ZJOI2016」大森林
  3. 如何减少idea的内存消耗
  4. 深度解读Helm 3: 犹抱琵琶半遮面
  5. Knative Tracing 介绍
  6. mysql 优化 1
  7. oracle中=&gt;是什么意思呢?
  8. 2018-9-28-WPF-自定义-TextBoxView-的-Margin-大小
  9. 用mysql查询某字段是否有索引
  10. springboot2多数据源完整示例