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>
using namespace std;
#define INIT ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
#define int ll
int t, n, m, k, a[300010], q, l, r;
int d[20];
int32_t main(){
INIT
cin>>t;
while(t--){
cin>>k;
for(int i=1; i<=9; i++){
cin>>d[i];
}
int dmax=0;
for(int i=1; i<=9; i++){
if(d[i]>0){dmax=max(dmax, i);}
}
string suf=""; suf.pb('0'+dmax);
d[dmax]--;
dmax=0;
for(int i=9; i>=1; i--){
if(d[i]>0){dmax=i; break;}
}
int sum=0; for(int i=1; i<dmax; i++){if(sum>=d[dmax]){break;} sum+=d[i]; }
if(sum>=d[dmax]){
for(int i=1; (i<dmax) && (d[dmax]>0); i++){
while( (d[i]>0) && (d[dmax]>0) ){cout<<dmax<<i; d[i]--; d[dmax]--;}
}
}
for(int i=1; i<=9; i++){
for(int j=1; j<=d[i]; j++){cout<<i;}
}
cout<<suf;
cout<<"\n";
}
return 0;
}
# | 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... |