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.
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.
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.
5
100
70
Y 25
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.
3
200000
199998
N
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.
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.
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 the non-negative integer, \(T\), which is the athlete's overall score.
7
10
8
0
10
3
75
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\).
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.
Red candy wins against green candy
.
Green candy wins against blue candy
.
Blue candy wins against red candy
.
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.
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\) |
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.
RRR
RGBB
2
5
| Candy Lines | Description | Summary |
|---|---|---|
|
Ngoc: Minh: |
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: Minh: |
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: Minh: |
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: Minh: |
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: |
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. |
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.
Given the movements taken by the snail, your job is to determine how many times the snail enters a slimy square.
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 the non-negative integer, \(T\), which is the number of times the snail enters a slimy square.
3
S2
N2
S3
4
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.
3
S2
W15
N20
0
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.
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).
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.
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.
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\) |
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.
10
3
4
8 0
1 1
4 2
4
10
7
1
Y
N
N
Y
The input describes the following picture of the parking garage.
Parking spots \(4\) and \(1\) are illuminated by at least one light.
Parking spots \(10\) and \(7\) are not illuminated by any light.