easy 写法。

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL _INF = 0xc0c0c0c0c0c0c0c0;
const LL mod = (int)1e9+;
const int N = 2e5 + ;
int h[N], n, k, m;
LL pre[N], sum[N];
LL cost[][N];
LL Get(int l, int r){
return pre[r] - pre[l] - (r-l) * sum[l];
}
priority_queue<LL, vector<LL>, greater<LL> > pq;
void solve(LL pre[], LL now[], int L, int R, int l, int r){
if(l > r) return ;
int mid = l+r >> ;
now[mid] = _INF;
int p = L;
for(int i = min(mid, R); i >= L; --i){
if(pre[i] - Get(i, mid) > now[mid]){
now[mid] = pre[i] - Get(i, mid);
p = i;
}
}
solve(pre, now, L, p, l, mid - );
solve(pre, now, p, R, mid + , r);
}
int main(){
int T;
scanf("%d", &T);
while(T--){
scanf("%d%d%d", &n, &k, &m);
for(int i = ; i <= n; ++i){
scanf("%d", &h[i]);
sum[i] = sum[i-] + h[i];
pre[i] = pre[i-] + sum[i];
cost[][i] = -pre[i];
pq.push(1ll * (n - i + ) * h[i]);
if(pq.size() > m) pq.pop();
}
int now = , pre = ;
for(int i = ; i <= k; ++i){
swap(now, pre);
solve(cost[pre], cost[now], , n, , n);
}
LL ans = cost[now][n];
while(!pq.empty()) {ans += pq.top(); pq.pop();}
printf("%lld\n", ans);
}
return ;
}

最新文章

  1. python基础之编码问题
  2. ORA-12519: TNS:no appropriate service handler found 解决(转)
  3. multiple definition of `err_sys&#39; 《UNIX环境高级编程》
  4. redis删除list中指定index的值
  5. import和from import陷阱一
  6. js实现堆排序
  7. SQL Server 2008导入、导出数据库
  8. MyBatis返回主键,MyBatis Insert操作返回主键
  9. HDU 3572 最大流
  10. 教你怎么去一个APP的JSON数据,你懂的
  11. React之jsx转js
  12. c++ --&gt; 父类与子类间的继承关系
  13. Linux - mail
  14. Python3 调试技巧 —— 死循环
  15. 如何清理Docker占用的磁盘空间?(转载)
  16. FPM六:接五,跳转到明细
  17. Pytho的历史和语言介绍
  18. Linux安装gcc/g++
  19. Java SubString截取字符串
  20. P1481 魔族密码 (LIS)

热门文章

  1. 【Intellij】导入 jar 包
  2. 【SQL数据库设计】数据库设计【小型数据库】
  3. Java动态,安全追踪工具
  4. S2:c#继承
  5. 【React踩坑记二】react项目实现JS路由跳转
  6. k8s+istio:流量控制之灰度发布
  7. Ubuntu 10.04下实现双网卡负载均衡
  8. WPF中TimeSpan的坑
  9. Tomcat中文乱码问题
  10. R 包 rgl 安装失败, 报错 X11 not found but required, configure aborted 及解决方法