修剪草坪
https://www.acwing.com/problem/content/description/1089/
https://class.51nod.com/Html/Textbook/ChapterIndex.html#textbookId=126&chapterId=337
由于是连续的会罢工,所以每次我们考虑的就是连续一段奶牛工作。
如果
但是如果
注意不超过
需要分配完所有的,所以不能只对
#include<iostream>
using namespace std;
const int N=100010;
int n,k,a[N],q[N];
typedef long long ll;
ll sum,f[N],ans=1e18;
int main(){
#ifdef LOCAL
freopen("1.txt","r",stdin);
#endif
#ifndef LOCAL
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
#endif
cin>>n>>k;
for(int i=1;i<=n;++i)cin>>a[i],sum+=a[i];
int hh=0,tt=0;
for(int i=1;i<=n+1;++i){
while(hh<=tt&&q[hh]<i-k-1)++hh;
f[i]=a[i]+f[q[hh]];
while(hh<=tt&&f[q[tt]]>=f[i])--tt;
q[++tt]=i;
}
cout<<sum-f[n+1];
return 0;
}
本文作者:wscqwq
本文链接:https://www.cnblogs.com/wscqwq/p/18319718
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
2023-07-23 AlmostSorted
2023-07-23 YetAnotherGridTask
2023-07-23 Defect-freeSquares