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 lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define uint unsigned int
using namespace std;
int main() {
#ifdef HOME
ifstream cin("A.in");
ofstream cout("A.out");
#endif
int t, i, k;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> t;
while(t--) {
cin >> k;
vector <int> num(10);
for(i = 1; i <= 9; i++) {
cin >> num[i];
}
string b;
int cur = 0;
for(i = 9; i >= 1; i--) {
while(num[i] > 0 && cur < k - 1) {
cur++;
b.push_back(i + '0');
num[i]--;
}
}
reverse(b.begin(), b.end());
vector <string> a;
for(i = 9; i >= 1; i--) {
if(num[i]) {
a.resize(num[i], string(1, i + '0'));
num[i] = 0;
break;
}
}
int sz = a.size(), pos = (int)a.size() - 1;
int dig = 1, last = 10;
while(dig < 10) {
while(dig < 10 && num[dig] == 0) {
dig++;
}
if(dig < 10) {
if(last < dig) {
sz = pos + 1;
}
last = dig;
num[dig]--;
a[pos].push_back(dig + '0');
pos = (pos == 0 ? sz - 1 : pos - 1);
}
}
for(auto &it : a) {
cout << it;
//cerr << it;
}
cout << b << "\n";
//cerr << b << "\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... |