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>
#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];
}
vector<int> lastK;
int _K = K-1;
int big = 9;
while(_K--){
while(cnt[big] == 0) big--;
cnt[big]--;
lastK.push_back(big);
}
S -= (K-1);
vector<int> front;
if(cnt[2] == 0){
front.assign(S,1);
}
else if(cnt[1] == 1){
front.assign(S,2);
}
else if(cnt[1] >= cnt[2]){
int grp = S / cnt[2];
for(int i = 1;i <= S;i++){
if(i % grp == 0) front.push_back(2);
else front.push_back(1);
}
reverse(all(front));
}
else{
int grp = S / cnt[1];
if(S % cnt[1] != 0) grp++;
for(int i = 0;i < S;i++){
if(i % grp == 0) front.push_back(1);
else front.push_back(2);
}
reverse(all(front));
}
for(int x : front) cout << x;
reverse(all(lastK));
for(int x : lastK) cout << x;
cout << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |