/*
* 正难则反
* f[i] 表示前 i 个数中被删除的数的最小和
* f[i] = min(f[j]) + num, i - k + 1 <= j < i;
* 单调队列维护
*/
#include <bits/stdc++.h> #define LL long long const int N = 1e5 + ; LL tot, d, n, k;
LL p[N], head = , tail = ;
LL q[N], f[N], ans; int main() {
std:: cin >> n >> k;
for(int i = ; i <= n; ++ i)
{
std:: cin >> d;
tot += d;
f[i] = q[head] + 1LL * d;
while(head <= tail && q[tail] >= f[i]) tail --;
q[++ tail] = f[i], p[tail] = i;
while(head <= tail && p[head] < i - k) head ++;
}
for(int i = n - k; i <= n; ++ i) ans = std:: max(ans, 1LL * tot - 1LL * f[i]);
printf("%lld", ans);
}

luogu2034的更多相关文章

随机推荐

  1. System函数的使用说明

    #inlcude<stdlib.h> int system(const char* command) 功能:在已经运行的程序中调用另一个外部程序 参数:外部可执行程序的名字 返回值:不同系 ...

  2. S04_CH01_搭建工程移植LINUX/测试EMMC/VGA

    S04_CH01_搭建工程移植LINUX/测试EMMC/VGA 1.1概述: 本章内容是在已经提供安装了VIVADO2015.4 的ubuntu系统下,进行.大家可以下周我们已经提供的虚拟机镜像,我们 ...

  3. Windows 32位-调试与反调试

    1.加载调试符号链接文件并放入d:/symbols目录下. 0:000> .sympath srv*d:\symbols*http://msdl.microsoft.com/download/s ...

  4. Visual Studio 2017修改编码UTF-8

    转载自:https://blog.csdn.net/qq_36848370/article/details/82597157 VS 2017隐藏了高级保存功能,导致没办法直接去设置代码编码 UTF-8 ...

  5. IP-reputation feature

    IP-reputation feature https://blog.norz.at/citrix-netscaler-ip-reputation-feature/ I recently had to ...

  6. Django2.0 开始一个项目

    python项目运行环境: 安装虚拟环境工具   pip install virtualenv 使用虚拟环境: 创建虚拟环境: virtualenv  <虚拟环境名称> 进去虚拟环境: S ...

  7. VBA教程(一)

    VBA代表Visual Basic for Applications,它是一个来自Microsoft的事件驱动的编程语言. 现在它主要用于Microsoft Office应用程序,如MSExcel,M ...

  8. html5+css3 快速学习

    http://kuai.qietu.com/books/html5_preview/index.htm#slide1

  9. swith-case 日历

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  10. [Selenium3+python3.6]自动化测试1-安装

    参考文档: http://www.cnblogs.com/yoyoketang/p/6123890.html 安装环境: win7+Py3.6 +FF45 (ESR version) +seleniu ...