# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
859725 | activedeltorre | Peru (RMI20_peru) | C++14 | 1 ms | 2396 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>
#include "peru.h"
using namespace std;
priority_queue<pair<long long,long long> >pq;
priority_queue<pair<long long,long long> >pq2;
long long dp[2500005];
int solve(int n, int k, int* v)
{
long long maxim=0,a,b,i;
for(i=0;i<k;i++)
{
maxim=max(maxim,1LL*v[i]);
dp[i]=maxim;
pq.push({v[i],i});
pq2.push({-maxim,i});
}
for(i=k;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-1]=1e9;
for(i=n+k-2;i>=0;i--)
{
dp[i]=min(dp[i],dp[i+1]);
}
long long suma=0,mod=1000000007;
for(i=0;i<n;i++)
{
suma=(suma*23+dp[i])%mod;
}
return suma;
}
/*
#include<iostream>
//#include "peru.h"
using namespace std;
static int s[2500005];
static int n, k;
int main(){
cin>> n >> k;
for(int i = 0; i < n; i++){
cin>> s[i];
}
int ans = solve(n, k, s);
cout<< ans <<"\n";
return 0;
}
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |