Sereja and Number Division 2
All submissions for this problem are available.
Read problems statements in Mandarin Chinese and Russian.
Sereja has an integer number A that doesn't contain zeroes in its decimal form. Also he has N integers B, B, ..., B[N].
Let us first define function f for a number A as follows. .
Now he has to reorder the digits of A such that f(A) is minimum. Please help him in finding most optimal A.
- First line contain a single integer T denoting number of test cases. Then T tests follow.
- First line of each test case contains an integer A.
- Next line contains an integer N.
- Next line contains N integers B, B, ..., B[N].
OutputFor each test case, output optimal value of A after reordering digits in a single line.
Input: 2 123 2 2 3 123457 1 10 Output: 312 754312
Let Y denotes your score for the problem. Y is defined as sum of f(optimal A)) for all test cases. You objective is to make Y as small as possible.
Tests generation Plan
Test set contains five official test cases. During the contest, your solution will be tested only on the first test. After the end of contest, it will be re-judged on the full test set.
Length of number A is generated randomly. All digits of it are also chosen randomly.
In all test cases N is equal to 100.
To generate array B, first we chose an integer R between 1 and 106 inclusive. Note that R is not randomly generated, it will be manually selected. Then all elements of array B are chosen in range 1..R randomly.
|Tags||challenge, jan15, sereja|
|Time Limit:||5 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, PYP3, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.