University of Waterloo Logo and CEMC Banner

2026 Canadian Computing Competition
Junior Problems

Problem J1: Concert Tickets

Problem Description

Besa wants to buy tickets for the upcoming Saylor Twift concert.

Given the total number of tickets for the concert and the number of tickets other people have purchased, your job is to determine whether or not Besa can buy her desired number of tickets.

Input Specification

The first line of input contains a positive integer, \(B\), representing the number of tickets Besa wants to buy. The second line contains a positive integer, \(T\), representing the total number of tickets for the concert. The third line contains a positive integer, \(P\), where \(P \leq T\), representing the number of tickets other people have purchased.

Output Specification

If Besa cannot buy \(B\) tickets, output N. Otherwise, output Y, followed by a single space, followed by the number of tickets that would remain after Besa buys \(B\) tickets.

Sample Input 1

5
100
70

Output for Sample Input 1

Y 25

Explanation of Output for Sample Input 1

There are a total of \(100\) tickets for the concert. Besa wants to buy \(5\) tickets and other people have purchased \(70\) tickets. So, \(100 - 75 = 25\) tickets would remain after Besa buys \(5\) tickets.

Sample Input 2

3
200000
199998

Output for Sample Input 2

N

Explanation of Output for Sample Input 2

There are a total of \(200\,000\) tickets for the concert. Besa wants to buy \(3\) tickets and other people have purchased \(199\,998\) tickets. So, Besa cannot buy \(3\) tickets.

Problem J2: Olympic Scores

Problem Description

An athlete participating in an Olympic event is scored by a panel of five judges. Each judge gives the athlete an integer score from \(0\) to \(10\) (inclusive).

To ensure that the scoring is fair, one occurrence of the highest score is removed and one occurrence of the lowest score is removed. The athlete's overall score is then determined by summing the three remaining scores and multiplying this total by the event's designated difficulty factor.

Given the scores from the panel of judges and the event's difficulty factor, your job is to determine the athlete's overall score.

Input Specification

The first five lines of input contain the scores from the five judges: \(S_1,\,S_2,\,S_3,\,S_4\), and \(S_5\). Each score will be an integer between \(0\) and \(10\) (inclusive).

The sixth line of input contains a positive integer, \(D\), representing the event's difficulty factor.

Output Specification

Output the non-negative integer, \(T\), which is the athlete's overall score.

Sample Input

7
10
8
0
10
3

Output for Sample Input

75

Explanation of Output for Sample Input

The five scores are \(7, 10, 8, 0, 10\). After removing one occurrence of the highest score and the only occurrence of the lowest score, the three remaining scores are \(7, 8, 10\). Therefore, the athlete's overall score is \((7 + 8 + 10) \times 3 = 75\).

Problem J3: Creative Candy Consumption

Problem Description

Ngoc and Minh devised a creative way to eat candy that comes in three different colours: red, green, and blue.

They begin by arranging some coloured candies into a line. Then, the candy at the front of Ngoc's line is compared to the candy at the front of Minh's line. If both candies are the same colour, then Ngoc and Minh each eat the candy at the front of their own line. If the candies are different colours, then the person with the winning candy eats the losing candy, and the winning candy stays at the front of its line.

This process of comparing and eating candy repeats until there is at least one empty line of candy. When that happens, if one person still has candy left in their line, then that person eats all of their leftover candy.

Your job is to determine how much candy each person eats.

Input Specification

The first line of input contains a sequence of \(N\) letters, representing Ngoc's line of candy. The second line of input contains a sequence of \(M\) letters, representing Minh's line of candy. Each letter will be an uppercase R, G, or B representing the colours red, green, and blue, respectively. The first letter in each sequence represents the colour of the candy at the front of that person's line. (There will always be at least one letter in each sequence.)

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

Marks Description Bounds
\(2\) Ngoc and Minh each have one candy. \(N = 1\) and \(M = 1\)
\(4\) Either Ngoc's line will empty first, or both lines will empty at the same time. Ngoc and Minh could have many candies. \(N \leq 50\) and \(M \leq 50\)
\(7\) Ngoc and Minh could have many candies. \(N \leq 50\) and \(M \leq 50\)
\(2\) Ngoc and Minh could have an absurd amount of candy. \(N \leq 1\,000\,000\) and \(M \leq 1\,000\,000\)

Output Specification

There will be two lines of output.

On the first line, output the number of candies Ngoc eats. On the second line, output the number of candies Minh eats.

Sample Input

RRR
RGBB

Output for Sample Input

2
5

Explanation of Output for Sample Input

Candy Lines Description Summary

Ngoc: red candy red candy red candy

Minh: red candy green candy blue candy blue candy

Both people have red candy at the front of their lines. Ngoc eats her red candy and Minh eats his red candy. So far, Ngoc has eaten \(1\) candy and Minh has eaten \(1\) candy.

Ngoc: red candy red candy

Minh: green candy blue candy blue candy

Ngoc's red candy wins against Minh's green candy. Ngoc eats Minh's green candy. So far, Ngoc has eaten \(2\) candies and Minh has eaten \(1\) candy.

Ngoc: red candy red candy

Minh: blue candy blue candy

Minh's blue candy wins against Ngoc's red candy. Minh eats Ngoc's red candy. So far, Ngoc has eaten \(2\) candies and Minh has eaten \(2\) candies.

Ngoc: red candy

Minh: blue candy blue candy

Minh's blue candy wins against Ngoc's red candy. Minh eats Ngoc's red candy. So far, Ngoc has eaten \(2\) candies and Minh has eaten \(3\) candies.

Ngoc:

Minh: blue candy blue candy

Ngoc's line of candy is empty, so the process ends. Minh eats his remaining blue candies. In total, Ngoc eats \(2\) candies and Minh eats \(5\) candies.

Problem J4: Snail Path

Problem Description

A snail is crawling across an infinite grid of equally sized squares. It can crawl horizontally (east and west) or vertically (north and south), but it cannot crawl diagonally.

As the snail crawls, it leaves a trail of slime which makes the squares of the grid it touches slimy.

For example, after the snail below crawls east \(3\) squares, there will be \(4\) slimy squares as shown.

A snail in one square of a grid. This square is coloured green.

The snail moves 3 squares to the right in the grid. The starting square, the ending square, and the two squares in between are coloured green.

Given the movements taken by the snail, your job is to determine how many times the snail enters a slimy square.

Input Specification

The first line of input contains a positive integer, \(M\), representing the number of movements taken by the snail.

The next \(M\) lines will specify the snail's movements, in order. Each movement will contain an uppercase directional letter (N, E, S, or W), followed by a positive integer less than or equal to 20 representing the number of squares the snail crawls in that direction.

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

Marks Description Bounds
\(4\) The snail will never crawl north or west of its initial position and will stay close to its initial position. \(M \leq 20\)
\(3\) The snail will stay close to its initial position. \(M \leq 20\)
\(6\) The snail may crawl quite far from its initial position. \(M \leq 1200\)
\(2\) The snail may crawl extremely far from its initial position. \(M \leq 200\,000\)

Output Specification

Output the non-negative integer, \(T\), which is the number of times the snail enters a slimy square.

Sample Input 1

3
S2
N2
S3

Output for Sample Input 1

4

Explanation of Output for Sample Input 1

The diagram shows the snail's path. Whenever the snail enters a slimy square, a numbered circle is placed along the path.

Notice that a single slimy square can be entered multiple times.

Four adjacent squares in one column are coloured green. A path begins in the top (1st) square and moves down through the 2nd square to the 3rd square. From here, the path moves back up through the 2nd square, marked with a 1, then back up to the 1st square, marked with a 2, then back down through the 2nd and 3rd squares, marked with a 3 and a 4, respectively, and ends in the bottom square.

Sample Input 2

3
S2
W15
N20

Output for Sample Input 2

0

Explanation of Output for Sample Input 2

The snail's path will consist of \(38\) slimy squares. However, the snail never returns to a square after leaving it, so the snail never enters a slimy square.

Technical Notes

You might receive an unpredictable error message if your program uses too much memory.

Python 3 submissions for this problem will be evaluated using the standard interpreter python3 (Version 3.10.12) instead of pypy3 7.3.9 (Version 3.8.13).

Problem J5/S2: Beams of Light

Problem Description

Along one wall of a parking garage there are identical parking spots numbered from \(1\) to \(N\). A collection of lights illuminates the parking garage. Each light shines on some number of adjacent parking spots.

Parking spots numbered 1 through 10 in a row from left to right. A light is above spot 1 and shines on spots 1 and 2. A second light is above spot 4 and shines on spots 2 through 6. A third light is above spot 8 and shines only on spot 8.

You will be questioned about the parking spots. For each parking spot you are questioned about, your job is to determine whether or not it is illuminated by at least one light.

Input Specification

The first line of input contains a positive integer, \(N\), representing the number of parking spots. The second line contains a non-negative integer, \(L\), representing the number of lights. The third line contains a positive integer, \(Q\), representing the number of parking spots you will be questioned about.

The next \(L\) lines provide information about the \(L\) lights. Line \(i\) will contain two integers, \(P_i\) and \(S_i\), separated by a single space. The first integer, \(1 \leq P_i \leq N\), represents the number of the parking spot above which a light is hung. The second integer, \(0 \leq S_i \leq N\), represents the spread of the light's beam. Light \(i\) shines on the parking spot that is directly below it. It also shines on the \(S_i\) parking spots located on either side, unless there are fewer than \(S_i\) spots on a side, in which case all the spots on that side will be illuminated. There could be more than one light directly above a parking spot.

The next \(Q\) lines of input each contain a positive integer between \(1\) and \(N\) inclusive, representing the number of the parking spot you are questioned about.

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

Marks Number of Spots Number of Lights Number of Questions
\(1\) \(N \leq 50\) \(L \leq 1\) \(Q \leq 50\)
\(2\) \(N \leq 50\) \(L \leq 50\) \(Q \leq 50\)
\(3\) \(N \leq 50\) \(L \leq 500\,000\) \(Q \leq 500\,000\)
\(9\) \(N \leq 500\,000\) \(L \leq 500\,000\) \(Q \leq 500\,000\)

Output Specification

There will be one line of output for each of the \(Q\) parking spots you are questioned about.

On each of these lines, output Y if the corresponding parking spot is illuminated by at least one light, or N if the corresponding parking spot is not illuminated by any light.

Sample Input

10
3
4
8 0
1 1
4 2
4
10
7
1

Output for Sample Input

Y
N
N
Y

Explanation of Output for Sample Input

The input describes the following picture of the parking garage.

Parking spots numbered 1 through 10 in a row from left to right. A light is above spot 1 and shines on spots 1 and 2. A second light is above spot 4 and shines on spots 2 through 6. A third light is above spot 8 and shines only on spot 8.

Parking spots \(4\) and \(1\) are illuminated by at least one light.

Parking spots \(10\) and \(7\) are not illuminated by any light.