# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
607548 | chonka | Zalmoxis (BOI18_zalmoxis) | C++98 | 167 ms | 26548 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 ;
typedef long long ll ;
const int MAXN = 1000007 ;
int n , k ;
int a[ MAXN ] ;
stack < int > s ;
vector < pair < int , int > > v ;
void solve ( ) {
cin >> n >> k ;
for ( int i = 1 ; i <= n ; ++ i ) {
cin >> a[ i ] ;
}
int tp = 0 ;
for ( int i = 1 ; i <= n ; ++ i ) {
int x = a[ i ] ;
while ( s.empty ( ) == false && s.top ( ) < x ) {
int y = s.top ( ) ;
-- k ;
v.push_back ( { y , 1 } ) ;
while ( s.empty ( ) == false && s.top ( ) == y ) {
s.pop ( ) ;
++ y ;
}
s.push ( y ) ;
}
v.push_back ( { x , 0 } ) ;
while ( s.empty ( ) == false && s.top ( ) == x ) {
++ x ; s.pop ( ) ;
}
s.push ( x ) ;
}
while ( s.empty ( ) == false && s.top ( ) < 30 ) {
int y = s.top ( ) ;
-- k ;
v.push_back ( { y , 1 } ) ;
while ( s.empty ( ) == false && s.top ( ) == y ) {
s.pop ( ) ;
++ y ;
}
s.push ( y ) ;
}
for ( auto [ x , type ] : v ) {
if ( type == 0 ) { cout << x << " " ; }
else {
while ( s.empty ( ) == false ) { s.pop ( ) ; }
s.push ( x ) ;
while ( k > 0 ) {
int x = s.top ( ) ; s.pop ( ) ;
if ( x == 0 ) { cout << "0 " ; }
else {
-- k ;
s.push ( x - 1 ) ; s.push ( x - 1 ) ;
}
}
while ( s.empty ( ) == false ) {
cout << s.top ( ) << " " ;
s.pop ( ) ;
}
}
}
cout << "\n" ;
}
int main ( ) {
ios_base :: sync_with_stdio ( false ) ;
cin.tie ( NULL ) ;
int t = 1 ; // cin >> t ;
while ( t -- ) { solve ( ) ; }
return 0 ;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |