Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Task : _example
- Author : Phumipat C. [MAGCARI]
- Language: C++
- Created : 11 December 2022 [11:09]
- */
- #include<bits/stdc++.h>
- using namespace std;
- struct A{
- int l,id;
- bool operator < (const A&o) const{
- return l>o.l;
- }
- };
- priority_queue<A > heap;
- int dp[500010];
- int main(){
- int n,k;
- scanf("%d %d %d",&n,&k,&dp[1]);
- heap.push({dp[1],1});
- for(int i=2;i<=n;i++){
- scanf("%d",&dp[i]);
- while(!heap.empty() && i-heap.top().id>k) heap.pop();
- dp[i]+=heap.top().l;
- heap.push({dp[i],i});
- }
- printf("%d\n",dp[n]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment