이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 (int i = 0; i < n + k; i++)
cout << res[i] << ' ';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |