# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
859725 | 2023-10-10T14:38:12 Z | activedeltorre | Peru (RMI20_peru) | C++14 | 1 ms | 2396 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 2396 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 2396 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 2396 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |