Slice
Slice
More pizza
Hash Code practice problem
Problem description
You are organizing a Hash Code hub and want to order pizza for pa icipants. Luckily,
there is a nearby pizzeria with really good pizza.
The pizzeria has di erent types of pizza, and to keep the food o ering interesting, we
can only order at most one pizza of each type. Fo unately, there are many types of
pizza to choose from!
Each type of pizza has a speci ed size: the size is the number of pizza slices in it.
Based on the number of pa icipants, you estimated a maximum number of slices that
you want to order – in order to reduce waste, the goal is to order as many pizza slices
as possible, but not more than the maximum number.
File format
Each input data set is provided in a plain text le containing exclusively ASCII
characters with lines terminated with a single '\n' character (UNIX-style line endings).
When a single line contains multiple elements, they are separated by single spaces.
The rst line of the data set contains the following data:
● an integer M (1 ≤ M ≤ 109) – the maximum number of pizza slices to order
● an integer N (1 ≤ N ≤ 105) – the number of di erent types of pizza
The second line contains N integers: the number of slices in each type of pizza, in
non-decreasing order:
1
● 1 ≤ S0 ≤ S1 ≤ … ≤ SN-1 <= M
Example
Input file Description
S0 (2 slices) S1 (5 slices) S2 (6 slices) S3 (8 slices)
Submissions
File format
The output should contain two lines:
● The rst line should contain a single integer K (0 ≤ K ≤ N) – the number of
di erent types of pizza to order.
● The second line should contain K numbers – the types of pizza to order (the
types of pizza are numbered from 0 to N-1 in the order they are listed in the
input).
The total number of slices in the ordered pizzas must be less than or equal to M.
Example
Submission file Description
3 3 types of pizza
0 2 3 ordering pizzas: S0, S2 and S3
2
Scoring
The solution gets 1 point for each slice of pizza ordered.
For example, above we ordered 3 pizzas: S0, S2 and S3. We know that the slices of
each of these are 2, 6 and 8 correspondingly.
So the score is: 2+6+8 = 16 points
Note that there are multiple data sets representing separate instances of the
problem. The nal score for your team will be the sum of your best scores for the
individual data sets.
3