# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
362068 | shahriarkhan | K blocks (IZhO14_blocks) | C++14 | 595 ms | 81284 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<bits/stdc++.h>
using namespace std ;
const int INF = 1e9 ;
int main()
{
int n , k ;
scanf("%d%d",&n,&k) ;
int a[n+1] ;
for(int i = 1 ; i <= n ; ++i) scanf("%d",&a[i]) ;
pair<int,int> dp[n+1][k+1] ;
dp[0][0] = {0,0} ;
for(int i = 1 ; i <= n ; ++i) dp[i][0] = {INF,INF} ;
for(int j = 1 ; j <= k ; ++j)
{
stack<pair<int,int> > s ;
for(int i = j ; i <= n ; ++i)
{
dp[i][j] = {dp[i-1][j-1].first + dp[i-1][j-1].second , a[i]} ;
while(!s.empty() && s.top().second <= a[i])
{
if((s.top().first + a[i])<(dp[i][j].first + dp[i][j].second))
{
dp[i][j] = {s.top().first,a[i]} ;
}
s.pop() ;
}
if(!s.empty())
{
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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |