이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std ;
const int N = 1e6 + 7 ;
int n , k ;
int a[N] ;
int check(int x , bool build = 0 ){
int j = 0 ;
stack<int> st ;
st.push(x) ;
int ret = 1 ;
while(j < n){
if(st.size() == 0)return -1 ;
int tp = st.top() ;st.pop() ;
if(tp < a[j]){
if(build)cout<<tp <<" " ;
continue ;
}
else if(tp == a[j]){
if(build)cout<< tp <<" " ;
j++ ;
}
else{
st.push(tp - 1) ;
st.push(tp -1) ;
ret++;
}
}
if(build){
while(st.size()){
cout<<st.top()<<" " ;
st.pop() ;
}
}
return ret - n ;
}
int main(){
ios_base::sync_with_stdio(0) ;
cin.tie(0) ;
//freopen("in.in" , "r" , stdin) ;
cin>>n>>k ;
for(int i = 0 ; i < n ; i++)
cin>>a[i] ;
int l = 1 , r = 2000000 , ans = 0 ;
while(l <=r ){
int mid = (l + r) /2 ;
int chk = check(mid) ;
if(chk < k){
l = mid+1 ;
}else r = mid -1 , ans = mid;
}
check(ans , 1 ) ;
return 0 ;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |