FP - Finding password


Bom has a list of n favorite numbers which are birthday, driving license, passport number, etc After creating an email account, Bom wants to choose a password as the largest number P among all possible numbers generated by the combinations of k (1 <= k <= n) positive numbers in the favorite list so that P is divisible by 9.


Your task is writing a program to help find P the password for Bom’s email.


Input
The first line contains a positive integer T as the number of test cases in the input file. The
following lines describe information of each test case including:
• One line containing two positive integers n and k,
• n following lines are n favorite numbers.


Output
The output file contains T lines; each line is the solution of the corresponding test case that is
either password P or -1 in case of not finding a feasible number.


Limits
T <= 30
1 <= k <= n <= 100
1 <= all favorite numbers <= 10^6


Sample input
2
3 2
1
2
3
5 2
1
2
3
4
5


Sample output
-1
54


hide comments
luka_dzimba911: 2018-03-29 17:59:07

No since you have to combine k numbers and k is 2 in that example

hasan75: 2017-01-26 08:57:00

in the second sample case,the output should be 432.right??

mahmud2690: 2016-10-16 20:40:59

Input:
1
3 3
54 5 544
Output should be: 554544
Also note that, You can not use same number multiple times.

Prabhu Dayal Sahoo: 2015-10-14 14:14:10

Very strict time time limit I guess. STL string gives TLE.

parijat bhatt: 2015-05-26 07:01:42

those getting wrong ans check for
1
3 3
54 5 554

siva: 2015-04-07 05:55:13

i need solution for FP-finding password.please i try a lot.but i don't get the solution.please urgent

Aayush Agarwal: 2014-09-10 08:24:50

Awesome!!

Akash Waghela: 2014-06-30 19:56:35

Last edit: 2014-06-30 19:58:59
ISHANI: 2014-06-22 11:42:35

strong dp

Rishav Goyal: 2014-06-15 11:51:11

tough -~-


Added by:sieunhan
Date:2009-11-29
Time limit:0.129s-0.543s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 NODEJS OBJC PERL6 SQLITE VB.NET
Resource:Do Duc Dong - ACM Vietnam Practice