제출 #647049

#제출 시각아이디문제언어결과실행 시간메모리
647049LeonaRagingZalmoxis (BOI18_zalmoxis)C++14
0 / 100
108 ms10112 KiB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define ll long long
#define pb push_back
#define db(val) "[" #val " = " << (val) << "] "

const ll mod = 1e9 + 7;
const int maxn = 1e6 + 4;
const int INF = 1e9;

int n, k, a[maxn];
stack<int> st;
vector<int> myVec;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //freopen(".INP", "r", stdin);
    //freopen(".OUT", "w", stdout);
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= n; i++) {
        while (!st.empty()) {
            if (st.top() < a[i])
                myVec.pb(st.top()), st.pop();
            else if (st.top() == a[i])
                st.pop(), a[i]++;
            else break;
        }
        st.push(a[i]);
    }
    while (!st.empty() && st.top() != 30) {
        int x = st.top(); st.pop();
        myVec.pb(x); st.push(x + 1);
    }
    int sz = myVec.size();
    vector<int> res;
    for (int i = 0; i < (int)myVec.size(); i++) {
        if (sz < n + k && myVec[i] > 1) {
            sz--;
            for (int j = max(1, myVec[i] - (n + k) + sz); j < myVec[i]; j++) {
                res.pb(j), sz++;
                if (sz == n + k) break;
            }
        }
        else res.pb(myVec[i]);
    }
    for (auto i : res) cout << i << ' ';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...