Submission #32216

#TimeUsernameProblemLanguageResultExecution timeMemory
32216chonkaK blocks (IZhO14_blocks)C++98
0 / 100
139 ms87572 KiB
#include<iostream> #include<stdio.h> #include<stack> using namespace std ; #define inf 1000000007 #define MAXN 100007 #define MAXK 107 int n , k ; int a[ MAXN ] ; long long dp[ MAXN ][ MAXK ] ; long long vals[ MAXN ] ; long long pref[ MAXN ] ; void input ( ) { scanf ( "%d%d" , &n , &k ) ; int i ; for ( i = 1 ; i <= n ; i ++ ) { scanf ( "%d" , &a[ i ] ) ; } } void solve ( ) { stack < int > s ; int sz ; int i , j ; for ( i = 1 ; i <= n ; i ++ ) { dp[ i ][ 1 ] = max ( dp[ i - 1 ][ 1 ] , 1LL * a[ i ] ) ; } pref[ 0 ] = inf ; for ( j = 2 ; j <= k ; j ++ ) { while ( s.empty ( ) == false ) { s.pop ( ) ; } a[ j - 1 ] = inf ; s.push ( j - 1 ) ; sz = 1 ; for ( i = j ; i <= n ; i ++ ) { while ( s.empty ( ) == false && a[ s.top ( ) ] <= a[ i ] ) { sz -- ; s.pop ( ) ; } vals[ sz ] = dp[ s.top ( ) ][ j - 1 ] + a[ i ] ; pref[ sz ] = min ( pref[ sz - 1 ] , vals[ sz ] ) ; dp[ i ][ j ] = pref[ sz ] ; s.push ( i ) ; sz ++ ; } } printf ( "%lld\n" , dp[ n ][ k ] ) ; } int main ( ) { input ( ) ; solve ( ) ; return 0 ; }

Compilation message (stderr)

blocks.cpp: In function 'void input()':
blocks.cpp:19:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ( "%d%d" , &n , &k ) ;
                                ^
blocks.cpp:22:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf ( "%d" , &a[ i ] ) ;
                                  ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...