A regular box of cupcakes holds 8 cupcakes, while a small box holds 3 cupcakes. There are 28 students in a class and a total of at least 28 cupcakes. Your job is to determine how many cupcakes will be left over if each student gets one cupcake.
The input consists of two lines.
The first line contains an integer \(R\geq 0\), representing the number of regular boxes.
The second line contains an integer \(S \geq 0\), representing the number of small boxes.
Output the number of cupcakes that are left over.
2
5
3
The total number of cupcakes is \(2\times8 + 5\times3\) which equals 31. Since there are 28 students, there are 3 cupcakes left over.
2
4
0
The total number of cupcakes is \(2\times8 + 4\times3\) which equals 28. Since there are 28 students, there are no cupcakes left over.
Fergusonball players are given a star rating based on the number of points that they score and the number of fouls that they commit. Specifically, they are awarded \(5\) stars for each point scored, and \(3\) stars are taken away for each foul committed. For every player, the number of points that they score is greater than the number of fouls that they commit.
Your job is to determine how many players on a team have a star rating greater than \(40\). You also need to determine if the team is considered a gold team which means that all the players have a star rating greater than \(40\).
The first line of input consists of a positive integer \(N\) representing the total number of players on the team. This is followed by a pair of consecutive lines for each player. The first line in a pair is the number of points that the player scored. The second line in a pair is the number of fouls that the player committed. Both the number of points and the number of fouls, are non-negative integers.
Output the number of players that have a star rating greater than \(40\), immediately followed by a plus sign if the team is considered a gold team.
3
12
4
10
3
9
1
3+
The image shows the star rating for each player. For example, the star rating for the first player is \(12 \times 5 - 4 \times 3 = 48\).
All three players have a rating greater than \(40\) so the team is considered a gold team.
2
8
0
12
1
1
The image shows the star rating for each player.
Since only one of the two players has a rating greater than \(40\), this team is not considered a gold team.
The CCC harp is a stringed instrument with strings labelled A,B,...,T. Like other instruments, it can be out of tune.
A musically inclined computer science student has written a clever computer program to help tune the harp. The program analyzes the sounds produced by the harp and provides instructions to fix each string that is out of tune. Each instruction includes a group of strings, whether they should be tightened or loosened, and by how many turns.
Unfortunately, the output of the program is not very user friendly.
It outputs all the tuning instructions on a single line. For example,
the single line AFB+8HC-4
actually contains
two tuning instructions: AFB+8
and
HC-4
. The first instruction indicates that
harp strings A, F, and B should be tightened 8 turns, and the
second instruction indicates that harp strings H and C should be loosened 4 turns.
Your job is to take a single line of tuning instructions and make them easier to read.
There will be one line of input which is a sequence of tuning
instructions. Each tuning instruction will be a sequence of uppercase
letters, followed by a plus sign (+
) or minus
sign (-
), followed by a positive integer.
There will be at least one instruction and at least one letter per
instruction. Also, each uppercase letter will appear at most once.
The following table shows how the available 15 marks are distributed.
Marks Awarded | Maximum Input Values | Example Input | ||
---|---|---|---|---|
Number of Instructions | Number of Letters in an Instruction | Number of Turns | ||
5 marks | 1 | 20 | 9 | AFB+8 |
5 marks | 20 | 1 | 9 | A+8H-4 |
3 marks | 20 | 20 | 9 | AFB+8HC-4 |
2 marks | 20 | 20 | 999 999 | AFB+88HC-444 |
There will be one line of output for each tuning instruction. Each
line of output will consist of three parts, each separated by a single
space: the uppercase letters referring to the strings,
tighten
if the instruction contained a plus
sign or loosen
if the instruction contained a
minus sign, and the number of turns.
AFB+8HC-4
AFB tighten
8 HC loosen 4
The input contains two tuning instructions:
AFB+8
and HC-4
.
AFB+8SC-4H-2GDPE+9
AFB tighten 8
SC loosen 4
H loosen 2
GDPE tighten 9
The input contains four tuning instructions:
AFB+8
, SC-4
,
H-2
, and GDPE+9
.
A class has been divided into groups of three. This division into groups might violate two types of constraints: some students must work together in the same group, and some students must work in separate groups.
Your job is to determine how many of the constraints are violated.
The first line will contain an integer \(X\) with \(X \geq 0\). The next \(X\) lines will each consist of two different names, separated by a single space. These two students must be in the same group.
The next line will contain an integer \(Y\) with \(Y \geq 0\). The next \(Y\) lines will each consist of two different names, separated by a single space. These two students must not be in the same group.
Among these \(X+Y\) lines representing constraints, each possible pair of students appears at most once.
The next line will contain an integer \(G\) with \(G \geq 1\). The last \(G\) lines will each consist of three different names, separated by single spaces. These three students have been placed in the same group.
Each name will consist of between 1 and 10 uppercase letters. No two students will have the same name and each name appearing in a constraint will appear in exactly one of the \(G\) groups.
The following table shows how the available 15 marks are distributed at the Junior level.
Marks Awarded | Number of Groups | Number of Constraints |
---|---|---|
4 marks | \(G \leq 50\) | \(X \leq 50\) and \(Y = 0\) |
10 marks | \(G \leq 50\) | \(X \leq 50\) and \(Y \leq 50\) |
1 mark | \(G \leq 100\,000\) | \(X \leq 100\,000\) and \(Y \leq 100\,000\) |
The following table shows how the available 15 marks are distributed at the Senior level.
Marks Awarded | Number of Groups | Number of Constraints |
---|---|---|
3 marks | \(G \leq 50\) | \(X \leq 50\) and \(Y = 0\) |
5 marks | \(G \leq 50\) | \(X \leq 50\) and \(Y \leq 50\) |
7 marks | \(G \leq 100\,000\) | \(X \leq 100\,000\) and \(Y \leq 100\,000\) |
Output an integer between \(0\) and \(X+Y\) which is the number of constraints that are violated.
1
ELODIE CHI
0
2
DWAYNE BEN ANJALI
CHI FRANCOIS ELODIE
0
There is only one constraint and it is not violated: ELODIE and CHI are in the same group.
3
A B
G L
J K
2
D F
D G
4
A C G
B D F
E H I
J K L
3
The first constraint is that A and B must be in the same group. This is violated.
The second constraint is that G and L must be in the same group. This is violated.
The third constraint is that J and K must be in the same group. This is not violated.
The fourth constraint is that D and F must not be in the same group. This is violated.
The fifth constraint is that D and G must not be in the same group. This is not violated.
Of the five constraints, three are violated.
Ron wants to build a square pool in his square \(N\)-by-\(N\) yard, but his yard contains \(T\) trees. Your job is to determine the side length of the largest square pool he can build.
The first line of input will be an integer \(N\) with \(N\geq2\). The second line will be the positive integer \(T\) where \(T < N^2\). The remaining input will be \(T\) lines, each representing the location of a single tree. The location is given by two positive integers, \(R\) and then \(C\), separated by a single space. Each tree is located at row \(R\) and column \(C\) where rows are numbered from top to bottom from \(1\) to \(N\) and columns are numbered from left to right from \(1\) to \(N\). No two trees are at the same location.
The following table shows how the available 15 marks are distributed.
Marks Awarded | Length/Width of Yard | Number of Trees |
---|---|---|
3 marks | \(N \leq 50\) | \(T=1\) |
5 marks | \(N \leq 50\) | \(T \leq 10\) |
4 marks | \(N \leq 500\,000\) | \(T \leq 10\) |
3 marks | \(N \leq 500\,000\) | \(T \leq 100\) |
Output one line containing \(M\) which is the largest positive integer such that some \(M\)-by-\(M\) square contained entirely in Ron’s yard does not contain any of the \(T\) trees.
5
1
2 4
3
A picture of the yard is below. The location of the tree is marked by and one of several \(3\)-by-\(3\) squares that do not contain the tree is highlighted. All larger squares contain a tree.
15 8 4 7 4 1 14 11 10 6 13 4 4 10 10 3 9 14
7
A picture of the yard is below. The location of each tree is marked by and one of several \(7\)-by-\(7\) squares that do not contain a tree is highlighted. All larger squares contain a tree.