0% found this document useful (0 votes)
66 views

Slice

The document describes a pizza ordering problem for a Hash Code event. Participants need to order pizza from a nearby pizzeria, which offers different types of pizza with varying slice counts. The goal is to order as many slices as possible, up to a maximum amount, by selecting at most one pizza of each type. Sample input and output formats are provided, with the score being the total number of slices ordered. Multiple data sets will be evaluated and the final score is the sum of the best scores per set.

Uploaded by

blahblah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views

Slice

The document describes a pizza ordering problem for a Hash Code event. Participants need to order pizza from a nearby pizzeria, which offers different types of pizza with varying slice counts. The goal is to order as many slices as possible, up to a maximum amount, by selecting at most one pizza of each type. Sample input and output formats are provided, with the score being the total number of slices ordered. Multiple data sets will be evaluated and the final score is the sum of the best scores per set.

Uploaded by

blahblah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

 

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. 

Input data set 

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 ≤ S0 ≤ S1 ≤ … ≤ SN-1 <= M 

Example 
Input file Description

17 4 17 slices maximum, 4 di erent types of pizza 


2 5 6 8 type 0 has 2 slices, type 1 has 5, type 2 has 6, and type 3 has 8 slices 

 
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 


 

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.  

You might also like