Submission #861808

#TimeUsernameProblemLanguageResultExecution timeMemory
861808iskhakkutbilimZalmoxis (BOI18_zalmoxis)C++17
0 / 100
144 ms10804 KiB
#include <bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define all(a) a.begin(), a.end()

int n, k;
vector<pair<int, int> > ans;
int st[31];
void f(int x, int depth){
//	cout << x << ' ' << depth << '\n';
if(x <= 0) assert(false);
	int mn = 1;
	while(st[mn] <= 0 && x >= mn) mn++;
//	cout << mn << '\n';
	if(x > mn){
		f(x-1, depth + 1);
		f(x-1, depth + 1);
	}else{
		ans.push_back({x, depth});
		st[x]--;
//		cout << "del " << x << '\n';
	}
}


main(){
   ios::sync_with_stdio(0);
   cin.tie(0); cout.tie(0);
	cin >> n >> k;
	for(int i = 0;i < n; i++){
		int x; cin >> x;
		st[x]++;
	}
	f(30, 0);
//	if(ans.size() != (n + k)){
//		assert(false);
//	}else{
		sort(all(ans), [&](pair<int, int> A, pair<int, int> B){
			return A.ss < B.ss;	
		});
		for(auto [x, y] : ans) cout << x << ' ';
//	}
	return 0;
}

Compilation message (stderr)

zalmoxis.cpp:28:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   28 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...