University of Waterloo Logo and CEMC Banner

2024 Canadian Computing Competition
Junior Problems

Conveyor Belt Sushi

Problem Description

There is a new conveyor belt sushi restaurant in town. Plates of sushi travel around the restaurant on a raised conveyor belt and customers choose what to eat by removing plates.

Each red plate of sushi costs \(\$3\), each green plate of sushi costs \(\$4\), and each blue plate of sushi costs \(\$5\).

        

Your job is to determine the cost of a meal, given the number of plates of each colour chosen by a customer.

Input Specification

The first line of input contains a non-negative integer, \(R\), representing the number of red plates chosen. The second line contains a non-negative integer, \(G\), representing the number of green plates chosen. The third line contains a non-negative integer, \(B\), representing the number of blue plates chosen.

Output Specification

Output the non-negative integer, \(C\), which is the cost of the meal in dollars.

Sample Input

0
2
4

Output for Sample Input

28

Explanation of Output for Sample Input

This customer chose \(0\) red plates, \(2\) green plates, and \(4\) blue plates. Therefore, the cost of the meal in dollars is \(0 \times 3 + 2 \times 4 + 4 \times 5 = 28\).

Problem J2: Dusa And The Yobis

Problem Description

Dusa eats Yobis, but only Yobis of a certain size.

If Dusa encounters a Yobi that is smaller than itself, it eats the Yobi, and absorbs its size. For example, if Dusa is of size \(10\) and it encounters a Yobi of size \(6\), Dusa eats the Yobi and expands to size \(10+6=16\).

If Dusa encounters a Yobi that is the same size as itself or larger, Dusa runs away without eating the Yobi.

Dusa is currently facing a line of Yobis and will encounter them in order. Dusa is guaranteed to eventually encounter a Yobi that causes it to run away. Your job is to determine Dusa’s size when this happens.

    

Input Specification

The first line of input contains a positive integer, \(D\), representing Dusa’s starting size.

The remaining lines of input contain positive integers representing the sizes of the Yobis in order.

Output Specification

Output the positive integer, \(R\), which is Dusa’s size when it eventually runs away.

Sample Input 1

5
3
2
9 
20
22
14

Output for Sample Input 1

19

Explanation of Output for Sample Input 1

Dusa is large enough to eat the Yobi of size \(3\). This brings Dusa’s size to \(8\). Dusa is large enough to eat the Yobi of size \(2\). This brings Dusa’s size to \(10\). Dusa is large enough to eat the Yobi of size \(9\). This brings Dusa’s size to \(19\). The Yobi of size \(20\) causes Dusa to run away.

Sample Input 2

10
10
3
5

Output for Sample Input 2

10

Explanation of Output for Sample Input 2

The Yobi of size \(10\) causes Dusa to run away, leaving its size unchanged.

Problem J3: Bronze Count

Problem Description

After completing a competition, you are struck with curiosity. How many participants were awarded bronze level?

Gold level is awarded to all participants who achieve the highest score. Silver level is awarded to all participants who achieve the second highest score. Bronze level is awarded to all participants who achieve the third highest score.

Given a list of all the scores, your job is to determine the score required for bronze level and how many participants achieved this score.

Input Specification

The first line of input contains a positive integer, \(N\), representing the number of participants.

Each of the next \(N\) lines of input contain a single integer representing a participant’s score.

Each score is between \(0\) and \(75\) (inclusive) and there will be at least three distinct scores.

The following table shows how the available \(15\) marks are distributed:

Marks Description Bound
\(6\) The scores are distinct and the number of participants is small. \(N \leq 50\)
\(7\) The scores might not be distinct and the number of participants is small. \(N \leq 50\)
\(2\) The scores might not be distinct and the number of participants could be large. \(N \leq 250\,000\)

Output Specification

Output a non-negative integer, \(S\), and a positive integer, \(P\), separated by a single space, where \(S\) is the score required for bronze level and \(P\) is how many participants achieved this score.

Sample Input 1

4
70
62
58
73 

Output for Sample Input 1

62 1

Explanation of Output for Sample Input 1

The score required for bronze level is \(62\) and one participant achieved this score.

Sample Input 2

8
75
70
60
70
70
60
75
70

Output for Sample Input 2

60 2

Explanation of Output for Sample Input 2

The score required for bronze level is \(60\) and two participants achieved this score.

Problem J4: Troublesome Keys

Problem Description

As Alex is typing, their keyboard is acting strangely. Two letter keys are causing trouble:

Alex presses the silly key at least once but they don’t necessarily press the quiet key.

Your job is to determine the troublesome keys and the wrong letter that is displayed. Luckily, this is possible because Alex never presses the silly key immediately after pressing the quiet key and Alex never presses the quiet key immediately after pressing the silly key.

Input Specification

There will be two lines of input. The first line of input represents the \(N\) keys Alex presses on the keyboard. The second line of input represents the letters displayed on the screen.

Both lines of input will only contain lowercase letters of the alphabet.

The following table shows how the available \(15\) marks are distributed.

Marks Description Bound
\(3\) The quiet key is not pressed. A small number of keys are pressed. \(N \leq 50\)
\(3\) The first troublesome key pressed is the silly key. A small number of keys are pressed. \(N \leq 50\)
\(5\) The first troublesome key pressed may be the silly key or the quiet key. A small number of keys are pressed. \(N \leq 50\)
4 The first troublesome key pressed may be the silly key or the quiet key. A large number of keys are pressed. \(N \leq 500\,000\)

Output Specification

There will be two lines of output.

On the first line, output the letter corresponding to the silly key and the wrong letter displayed on the screen when it is pressed, separated by a single space.

On the second line, output the letter corresponding to the quiet key if it is pressed. Output the dash character (-) if the quiet key is not pressed.

Sample Input 1

forloops 
fxrlxxps

Output for Sample Input 1

o x
-

Explanation of Sample Output 1

The letter corresponding to the silly key was the letter o. Each time it was pressed, the wrong letter x was displayed. The quiet key was not pressed.

Sample Input 2

forloops 
fxrlxxp

Output for Sample Input 2

o x
s

Explanation of Sample Output 2

The letter corresponding to the silly key was the letter o. Each time it was pressed, the wrong letter x was displayed. The quiet key corresponds to the letter s which was not displayed.

Sample Input 3

forloops 
frlpz

Output for Sample Input 3

s z
o

Explanation of Sample Output 3

The letter corresponding to the silly key was the letter s. Each time it was pressed, the wrong letter z was displayed. The quiet key corresponds to the letter o which was not displayed.

Problem J5: Harvest Waterloo

Problem Description

There is a wildly popular new harvest simulation game called Harvest Waterloo. The game is played on a rectangular pumpkin patch which contains bales of hay and pumpkins of different sizes. To begin the game, a farmer is placed at the location of a pumpkin.

The farmer harvests all pumpkins they can reach by moving left, right, up, and down throughout the patch. The farmer cannot move diagonally. The farmer can also not move through a bale of hay nor move outside of the patch.

Your job is to determine the total value of all the pumpkins harvested by the farmer. A small pumpkin is worth \(\$1\), a medium pumpkin is worth \(\$5\), and a large pumpkin is worth \(\$10\) dollars.

Input Specification

The first line of input is an integer \(R > 0\) which is the number of rows within the patch.

The second line of input is an integer \(C > 0\) which is the number of columns within the patch.

The next \(R\) lines describe the patch. Each line will contain \(C\) characters and each character will either represent a pumpkin size or a bale of hay: S for a small pumpkin, M for a medium pumpkin, L for a large pumpkin, or * for a bale of hay.

The next line of input is an integer \(A\) where \(0 \leq A < R\), and the last line of input is an integer \(B\) where \(0 \leq B < C\). Row \(A\) and column \(B\) is the starting location of the farmer and the top-left corner of the patch is row \(0\) and column \(0\).

The following table shows how the available \(15\) marks are distributed:

Marks Description Bound
\(1\) The patch is small and there are no bales of hay. \(R \times C \leq 100\)
\(4\) The patch is small and the bales of hay divide the entire patch into rectangular areas. \(R \times C \leq 100\)
\(5\) The patch is small and the bales of hay can be anywhere. \(R \times C \leq 100\)
\(5\) The patch is large and the bales of hay can be anywhere. \(R \times C \leq 100\,000\)

Output Specification

Output the integer, \(V\), which is the total value in dollars of all the pumpkins harvested by the farmer.

Sample Input 1

6 
6
**LMLS
S*LMMS
S*SMSM
******
LLM*MS
SSL*SS
5
1

Output for Sample Input 1

37

A 6 by 6 pumpkin patch. A person is standing in the sixth row and second column. A 2 by 3 group consisting of the first three pumpkins in the fifth and sixth rows is highlighted. This group is bordered by two edges of the patch and bales of hay, and it contains 2 small, 1 medium and 3 large pumpkins.

Explanation of Output for Sample Input 1

Starting at row 5 and column 1, the farmer can reach the 6 pumpkins in the highlighted area. They harvest 2 small pumpkins, 1 medium pumpkin, and 3 large pumpkins. The total value in dollars of this harvest is \(2 \times 1 + 1 \times 5 + 3 \times 10 = 37\).

Sample Input 2

6
6
**LMLS
S*LMMS
S*SMSM
***SLL
LLM*MS
SSL*SS
2
4

Output for Sample Input 2

88

A 6 by 6 pumpkin patch. A person is standing in the third row and fifth column. A group formed by the last four pumpkins in the first three rows, the last three in the fourth row, and the last two in the fifth and six rows is highlighted. The group is bordered by three edges of the patch and bales of hay, and it contains 8 small, 6 medium and 5 large pumpkins.

Explanation of Output for Sample Input 2

Starting at row \(2\) and column \(4\), the farmer can reach the \(19\) pumpkins in the highlighted area. They harvest \(8\) small pumpkins, \(6\) medium pumpkin, and \(5\) large pumpkins. The total value in dollars of this harvest is \(8 \times 1 + 6 \times 5 + 5 \times 10 = 88\).