1st question


Solution
void solve(int cs){
int N, X;
cin >> N >> X;
vi a(N);
cin >> a;
priority_queue<int> pq;
for(auto it : a) pq.push(it);
while(X--){
auto it = pq.top();
pq.pop();
pq.push(it/2);
}
int res = 0;
while(!pq.empty()){
res += pq.top();
pq.pop();
}
cout << res << endl;
}
2nd question



3rd question




4th question





Another slot
1st question


#include <iostream>
#include <vector>
#include <set>
std::vector<std::vector<int>> buildTower(int n, std::vector<int>& bricks) {
std::vector<std::vector<int>> result(n);
std::set<int> availableBricks;
int nextBrick = n;
for (int i = 0; i < n; ++i) {
availableBricks.insert(bricks[i]);
std::vector<int> dailyBricks;
while (!availableBricks.empty() && *availableBricks.rbegin() == nextBrick) {
dailyBricks.push_back(nextBrick);
availableBricks.erase(--availableBricks.end());
--nextBrick;
}
result[i] = dailyBricks;
}
return result;
}
int main() {
int n;
std::cin >> n;
std::vector<int> bricks(n);
for (int i = 0; i < n; ++i) {
std::cin >> bricks[i];
}
std::vector<std::vector<int>> result = buildTower(n, bricks);
for (const auto& dailyBricks : result) {
if (!dailyBricks.empty()) {
for (int brick : dailyBricks) {
std::cout << brick << " ";
}
}
std::cout << std::endl;
}
return 0;
}