#include <bits/stdc++.h>
using namespace std;
const int nx=1e6+5;
int n, k, a[nx], cnt;
stack<pair<int, int>> s;
vector<int> res[nx];
void insert(pair<int, int> x)
{
if (s.empty()) s.push(x);
else
{
if (s.top().first==x.first) s.pop(), insert({x.first+1, x.second});
else s.push(x);
}
}
void show(int x)
{
if (cnt==k) return cout<<x<<' ', void();
else cnt++, show(x-1), show(x-1);
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>k;
for (int i=1; i<=n; i++) cin>>a[i];
for (int i=1; i<=n; i++)
{
if (s.empty()) s.push({a[i], i});
else
{
while (s.top().first<a[i])
{
auto [x, y]=s.top();
s.pop();
res[y].push_back(x);
cnt++;
insert({x+1, y});
}
insert({a[i], i});
}
}
while (s.top().first<30)
{
auto [x, y]=s.top();
s.pop();
res[y].push_back(x);
cnt++;
insert({x+1, y});
}
for (int i=1; i<=n; i++)
{
cout<<a[i]<<' ';
for (auto x:res[i]) show(x);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |