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].
For 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:||ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 4.9.2, CPP14, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYPY, PYTH, PYTH 3.4, RUBY, SCALA, SCM chicken, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC|
Fetching successful submissions