Submission #258200

#TimeUsernameProblemLanguageResultExecution timeMemory
258200oolimryDevil's Share (RMI19_devil)C++14
14 / 100
75 ms2168 KiB
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using namespace std;
typedef pair<int,int> ii;

signed main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	
	int TC; cin >> TC;
	
	while(TC--){
		
		int K; cin >> K;
		int cnt[10];
		
		int S = 0;
		for(int i = 1;i <= 9;i++){
			cin >> cnt[i];
			S += cnt[i];
		}
		
		if(K == 2){
			int last = 0;
			int big = 9;
			while(cnt[big] == 0) big--;
			last = big;
			cnt[big]--;
			
			while(cnt[big] == 0) big--;
			S--;
			
			if(cnt[big]*2 > S){
				int r = big;
				while(S--){
					while(cnt[r] == 0) r--;
					cout << r;
					cnt[r]--;
				}
			}
			else{
				int l = 1, r = big;
				bool left = false;
				while(S--){
					if(left){
						while(cnt[l] == 0) l++;
						cout << l; 
						cnt[l]--;
					}
					else{
						while(cnt[r] == 0) r--;
						cout << r;
						cnt[r]--;
					}
					left = !left;
				}
			}
			
			cout << last;
			cout << '\n';
		}
	}
}


#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...