www 被大佬|

wscqwq

园龄:2年粉丝:2关注:3

修剪草坪

https://www.acwing.com/problem/content/description/1089/

https://class.51nod.com/Html/Textbook/ChapterIndex.html#textbookId=126&chapterId=337

由于是连续的会罢工,所以每次我们考虑的就是连续一段奶牛工作。

如果 fi 表示最大效率,需要求前缀和。

但是如果 fi 表示 i 罢工时前 i 的最小损失,那么只需要枚举工作段,然后加上损失。

注意不超过 k 不会罢工,所以是 (ik1,i)

需要分配完所有的,所以不能只对 fmin,最后可以加一个空的位置 n+1

#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 中国大陆许可协议进行许可。

posted @   wscqwq  阅读(3)  评论(0编辑  收藏  举报
历史上的今天:
2023-07-23 AlmostSorted
2023-07-23 YetAnotherGridTask
2023-07-23 Defect-freeSquares
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起