#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 3e3 + 2;
const int inf = 2e9;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, k;
cin >> n >> k;
vector<int> a(n + 1);
a[n] = 30;
stack<int> s;
vector<pair<int, int>> ans;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i <= n; i++) {
if (i == 0) {
ans.push_back({a[i], 0});
s.push(a[i]);
continue;
}
while (s.top() < a[i]) {
int x = s.top();
ans.push_back({x, 1});
k--;
s.push(x);
while (s.size() > 1) {
x = s.top(); s.pop();
if (x == s.top()) s.top()++;
else {s.push(x); break;}
}
}
int x = a[i];
ans.push_back({a[i], 0});
s.push(a[i]);
while (s.size() > 1) {
x = s.top(); s.pop();
if (x == s.top()) s.top()++;
else {s.push(x); break;}
}
}
function<void(int)> F = [&] (int x) {
int y = min((int)pow(2, x - 1) - 1, k);
k -= y;
int u = log2(y + 1);
int dif = y - pow(2, u) + 1;
for (int i = 1; i <= y + 1; i++) {
if (dif > 0) {
cout << x - u - 1 << sp << x - u - 1 << sp;
i += 1;
dif -= 1;
}
else cout << x - u << sp;
}
};
for (auto u : ans) {
if (u.first == 30) break;
if (u.second == 0) cout << u.first << sp;
else F(u.first);
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
134 ms |
16344 KB |
Output is correct |
2 |
Correct |
170 ms |
16296 KB |
Output is correct |
3 |
Correct |
133 ms |
16288 KB |
Output is correct |
4 |
Correct |
131 ms |
16360 KB |
Output is correct |
5 |
Correct |
141 ms |
16352 KB |
Output is correct |
6 |
Correct |
129 ms |
16276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
140 ms |
16224 KB |
Output is correct |
2 |
Incorrect |
132 ms |
16304 KB |
not a zalsequence |
3 |
Incorrect |
133 ms |
16364 KB |
not a zalsequence |
4 |
Correct |
135 ms |
16352 KB |
Output is correct |
5 |
Correct |
131 ms |
16356 KB |
Output is correct |
6 |
Correct |
132 ms |
16308 KB |
Output is correct |
7 |
Correct |
134 ms |
16352 KB |
Output is correct |
8 |
Correct |
132 ms |
16292 KB |
Output is correct |
9 |
Incorrect |
130 ms |
14536 KB |
not a zalsequence |
10 |
Incorrect |
98 ms |
7716 KB |
not a zalsequence |
11 |
Incorrect |
117 ms |
11596 KB |
not a zalsequence |
12 |
Incorrect |
65 ms |
2244 KB |
not a zalsequence |
13 |
Incorrect |
70 ms |
2252 KB |
not a zalsequence |
14 |
Correct |
63 ms |
2236 KB |
Output is correct |