## An Animal Contest 3 P2 - Monkey Potato

View as PDF

Points: 5 (partial)
Time limit: 2.0s
Memory limit: 256M

Authors:
Problem type

Daniel the monkey was hanging off his favourite branch while watching his favourite anime, when all of a sudden, a potato fell from the sky! Upon examining the potato, he notices distinct digits carved on it.

Daniel wants you to use some non-empty combination of digits from the potato to form a positive integer of length , with no leading zeros. He also tells you that you can use the same digit more than once. Additionally, Daniel doesn't remember if he should read numbers from left to right or right to left, so he tells you to make him an integer that reads the same either way!

In addition, Daniel doesn't like processing large integers, so he'll only accept the smallest possible answer. If it is impossible to satisfy this task, you'll have to tell him, and he will become a very sad monkey.

#### Constraints

All are distinct.

#### Input Specification

The first line of input will contain and separated by a single space.

The next line will contain space-separated integers, denoting the digits that you can use to construct the integer.

#### Output Specification

Output the minimum positive integer of length using some non-empty combination of the digits, or -1 if there is no valid answer.

#### Sample Input 1

5 6
3 1 2 5 4 9

#### Sample Output 1

11111

#### Explanation for Sample 1

It can be proven that is the smallest valid positive -digit integer that can be formed with the digits .

#### Sample Input 2

1 1
1

#### Sample Output 2

1

#### Sample Input 3

6 1
0

#### Sample Output 3

-1

• commented on Jan. 8, 2022, 2:20 p.m.

Don't you just hate it when you're watching anime and a potato falls on your head

• commented on Aug. 4, 2021, 8:29 a.m.

Could anyone advise me on why my output stops getting AC after Test Case #4 in Batch #2?

• commented on Aug. 5, 2021, 2:20 p.m. edited

A reminder that sharing solutions in the comments is strongly discouraged. Asking for help in DMOJ Slack or Discord is preferable.

Also, editorials exist for the purposes of discussing solutions...

• commented on Aug. 4, 2021, 12:05 p.m.

Try the case

1 2
0 1
• commented on Aug. 5, 2021, 8:18 a.m.

Thanks.

• commented on Aug. 4, 2021, 8:34 a.m.