# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
859723 | activedeltorre | Peru (RMI20_peru) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <queue>
using namespace std;
priority_queue<pair<long long,long long> >pq;
priority_queue<pair<long long,long long> >pq2;
long long v[2500005];
long long dp[2500005];
signed main()
{
long long n,i,j,k,l;
cin>>n>>k;
for(i=1;i<=n;i++)
{
cin>>v[i];
}
long long maxim=0,a,b;
for(i=1;i<=k;i++)
{
maxim=max(maxim,v[i]);
dp[i]=maxim;
pq.push({v[i],i});
pq2.push({-maxim,i});
}
for(i=k+1;i<=n+k-1;i++)
{
pq.push({v[i],i});
while(pq.top().second<=i-k)
{
pq.pop();
}
while(pq2.top().second<i-k)
{
pq2.pop();
}
a=pq.top().first;
b=pq2.top().first;
dp[i]=pq.top().first-pq2.top().first;
pq2.push({-dp[i],i});
}
dp[n+k]=1e9;
for(i=n+k-1;i>=1;i--)
{
dp[i]=min(dp[i],dp[i+1]);
}
long long suma=0,mod=1000000007;
for(i=1;i<=n;i++)
{
suma=(suma*23+dp[i])%mod;
}
cout<<suma;
return 0;
}