"Title description"
After winning the best lawn game in town a year ago, FJ became very lazy and never trimmed the lawn. Right now
The new round of the best lawn competition began again, FJ hope to win again.
However, FJ's lawn is very messy, so FJ can only get his cows to do the work. FJ has n
(1 <= N <= 100,000) only a row of cows, numbered 1 ... N. The efficiency of each cow is different,
The efficiency of cow I is e_i (0 <= e_i <=1,000,000,000).
Close to the cows are familiar, so if FJ arrange for more than K (1<=k<=n) only continuous cows, then these cows will strike
To party:). So now FJ needs your help to calculate the maximum efficiency that FJ can get, and in that scenario
No more than k cows in succession.
"Input Format"
* First line: Two integers separated by spaces N and K
* Second to N+1 line: line i+1 has an integer e_i
"Output Format"
* First line: A value that represents the maximum efficiency value that the FJ can get.
"Sample Input"
5 2
1
2
3
4
5
Input explanation:
FJ has 5 cows, and their efficiency is 1,2,3,4,5. They want to pick the cows with the greatest efficiency, but
He can't pick more than 2 consecutive cows.
"Sample Output"
12
FJ can choose a cow other than the third one, with a total efficiency of 1+2+4+5=12.
F[i]=min{f[j]+a[i]} (I-J<=K)
F[i] represents the minimum efficiency of loss when I do not select
1 #defineLL Long Long2#include <iostream>3 using namespacestd;4 5 ConstLL inf=0x7fffffffffffffffll;6 7 structData8 {9 LL num,v;Ten}q[100001]; One A intN,k,l,r; -LL ans,mn=inf,f[100001]; - inte[100001]; the - intMain () - { -Cin>>n>>K; + for(intI=1; i<=n;i++) -cin>>e[i],ans+=E[i]; + for(intI=1; i<=n;i++) A { atf[i]=e[i]+q[l].v; - while(q[r].v>f[i]&&l<=r) r--; -q[++r].v=F[i]; -q[r].num=i; - while(q[l].num<i-k&&l<=r) l++; - } in for(inti=n-k;i<=n;i++) -mn=min (mn,f[i]); tocout<<ans-mn<<Endl; + return 0; -}
[bzoj]2442 Mowing the lawn