Connection Status:
Competition Arena > TheNumbersLord
SRM 381 · 2007-12-08 · by Vasyl[alphacom] · Sorting
Class Name: TheNumbersLord
Return Type: String
Method Name: create
Arg Types: (vector<int>, int)
Problem Statement

Problem Statement

Recently, John had a dream where he was a lord in a world of positive integers. As with all lords, he had to solve a very difficult problem.

John has a list of positive integers. He must pick exactly n integers using this list and concatenate them in any order to produce the largest possible number. The same integer in the list can be chosen multiple times, but each integer must be chosen at least once.

You are given a int[] numbers and an int n. Return the largest possible integer that John can create as a String.

Notes

  • numbers may contain duplicate values. In this case, each integer must be chosen at least as many times as the number of its occurrences in numbers.

Constraints

  • numbers will contain between 1 and 50 elements, inclusive.
  • Each element of numbers will be between 1 and 1,000,000,000, inclusive.
  • n will be between the number of elements in numbers and 50, inclusive.
Examples
0)
{3,2,7}
3
Returns: "732"

Clearly, it is impossible to get a number greater than 732.

1)
{4, 7}
4
Returns: "7774"
2)
{1, 10, 100}
4
Returns: "110100100"

To get the largest possible number, John must use 100 twice.

3)
{4,4,4,4}
9
Returns: "444444444"

Here there is no choice for John at all.

4)
{1}
1
Returns: "1"

Submissions are judged against all 176 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class TheNumbersLord with a public method string create(vector<int> numbers, int n) · 176 test cases · 2 s / 256 MB per case

Submitting as anonymous