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;
const int N = 1e6 + 66;
vector<int> v[N] , a(N);
void func(int x , int k){
if(k == 0 || x == 0){
cout<<x<<" ";
return;
}
k--;
func(x-1 ,k);
func(x-1 ,k);
}
int32_t main()
{
int n,k;
cin>>n>>k;
for(int i=0;i<n;i++){
cin>>a[i];
}
a[n] = 30;
int cem = 0;
for(int i = 0; i < n; i++){
cem += (1<<a[i]);
while(__builtin_ctz(cem) < a[i+1]){
v[i].push_back(__builtin_ctz(cem));
cem += (cem & -cem);
k--;
}
}
for(int i=0;i<n;i++){
cout << a[i] << " ";
for(int x : v[i]){
func(x, k);
}
}
}
/*
1 1 2 2 3 3 4 4
1
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |