#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; bool rcmp(int a, int b) { return a>b; } typedef long long LL; class mypcmp { public: bool operator()(const int& a, const int& b) { return a> q; for (i=0; i=0; i--) { r = dp[i+1]; while(!q.empty()) { auto x = q.top(); if (x.second-i<=k) break; q.pop(); } if (!q.empty()) { auto x = q.top(); r = max(r, x.first-ss[i]); } dp[i]=r; q.push({dp[i+1]+ss[i], i+1}); } printf("%lld\n", dp[0]); return 0; }