# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
477323 | Alexandruabcde | Devil's Share (RMI19_devil) | C++14 | 85 ms | 7120 KiB |
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;
typedef pair <string, int> PSI;
int fr[10];
void do_Testcase () {
int K;
cin >> K;
for (int i = 1; i <= 9; ++ i )
cin >> fr[i];
string S;
int cif = 9;
for (int i = 1; i <= K-1; ++ i ) {
while (fr[cif] == 0) -- cif;
S += (cif + '0');
-- fr[cif];
}
reverse(S.begin(), S.end());
while (fr[cif] == 0) -- cif;
string pt_Max;
pt_Max.push_back('0' + cif);
PSI Max = {pt_Max, fr[cif]};
vector <PSI> v;
for (int i = 0; i < cif; ++ i ) {
if (fr[i] <= 0) continue;
string aux;
aux.push_back(i + '0');
v.push_back({aux, fr[i]});
}
for (int i = 0; i < v.size(); ++ i ) {
auto it = v[i];
while (it.second >= Max.second) {
Max.first += it.first;
it.second -= Max.second;
}
if (it.second > 0) {
v.push_back({Max.first + it.first, it.second});
Max.second -= it.second;
}
}
for (int i = 0; i < Max.second; ++ i )
cout << Max.first;
cout << S << '\n';
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
cin >> T;
for (; T; -- T )
do_Testcase();
return 0;
}
Compilation message (stderr)
# | 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... |