Your boss has asked you to add up a sequence of positive numbers to determine how much money your company made last year.
Unfortunately, your boss reads out numbers incorrectly from time to time.
Fortunately, your boss realizes when an incorrect number is read and says “zero”, meaning “ignore the current last number.”
Unfortunately, your boss can make repeated mistakes, and says “zero” for each mistake.
For example, your boss may say “One, three, five, four, zero, zero, seven, zero, zero, six”, which means the total is 7 as explained in the following chart:
Boss statement(s) | Current numbers | Explanation |
---|---|---|
“One, three, five, four” | 1, 3, 5, 4 | Record the first four numbers. |
“zero, zero” | 1, 3 | Ignore the last two numbers. |
“seven” | 1, 3, 7 | Record the number 7 at the end of our list. |
“zero, zero” | 1 | Ignore the last two numbers. |
“six” | 1, 6 | We have read all numbers, and the total is 7. |
At any point, your boss will have said at least as many positive numbers as “zero” statements. If all positive numbers have been ignored, the sum is zero.
Write a program that reads the sequence of boss statements and computes the correct sum.
The first line of input contains the integer
The output is one line, containing the integer which is the correct
sum of the integers read, taking the “zero” statements into
consideration. You can assume that the output will be an integer in the
range
4
3
0
4
0
0
10
1
3
5
4
0
0
7
0
0
6
7
A school team is trying to assign jerseys numbered
Each athlete has requested a specific jersey number and a preferred size. The athletes will not be satisfied with a jersey that is the wrong number or that is smaller than their preferred size. They will be satisfied with a jersey that is their preferred size or larger as long as it is the right number. Two students cannot be given the same jersey.
Your task is to determine the maximum number of requests that can be satisfied.
The first line of input is the integer
The second line of input is the integer
The next
The last
For 50% of the test cases,
For the remaining 50% of the test cases,
The output will consist of a single integer which is the maximum number of requests that can be satisfied.
4
3
M
S
S
L
L 3
S 3
L 1
1
Jersey 1 cannot be assigned because it is medium and athlete 3 requested large. No athlete requested jersey 2 or 4. Jersey 3 (small) can be assigned athlete 2 (small) but not athlete 1 (large).
For your birthday, you were given an airport.
The airport has
In order to keep the person who gave you the airport happy, you would like to maximize the number of planes starting from the beginning that can all dock at different gates.
The first line of input contains
The second line of input contains
The next
Note that for at least 40% of the marks for this question,
Output the maximum number of planes that can land starting from the beginning.
4
3
4
1
1
2
The first plane can go anywhere, but it is best to not put it into Gate 1. Notice that planes 2 and 3 both want to dock into Gate 1, so plane 3 is unable to dock.
4
6
2
2
3
3
4
4
3
The first two planes will dock in gates 1 and 2 (in any order). The third plane must dock at Gate 3. Thus, the fourth plane cannot dock anywhere, and the airport is closed, even though plane 5 would have been able to dock.
You are travelling on a ship in an archipelago. The ship has a convex
hull which is
You would like to travel from island
Additionally, you are in a hurry, so you would like to minimize the
amount of time necessary to reach island
The first line of input contains three integers
The next
The last line of input contains two integers
For 20% of marks for this question,
Output a single integer: the integer representing the minimal time
required to travel from
10 4 7
1 2 4 4
1 3 7 2
3 1 8 1
3 2 2 2
4 2 1 6
3 4 1 1
1 4 6 12
1 4
7
The path of length 1 from
3 3 3
1 2 5 1
3 2 8 2
1 3 1 3
1 3
-1
The direct path
The local pie shop is offering a promotion - all-you-can-eat pies! Obviously, you can’t pass up this offer.
The shop lines up
You are first allowed to insert each of the
Following this, you are allowed to take one walk along the new line of pies from left to right, to pick up your selection of all-you-can-eat pies! When you arrive at a pie, you may choose to add it to your pile, or skip it. However, because you’re required to keep moving, if you pick up a certain pie, you will not be able to also pick up the pie immediately after it (if any). In other words, you cannot eat consecutive pies in this combined list.
Being a pie connoisseur, your goal is to maximize the total amount of sugar in the pies you pick up from the line. How many grams can you get?
The first line of input contains the integer
The next line contains
For 20% of the marks for this question,
Output the maximum number of grams of sugar in all the pies that you are able to pick up.
5
10
12
6
14
7
3
1
8
2
44
Place the pies in the order
10, 1, 12, 2, 8, 6, 14, 7
(that is, insert the pie with 1 gram of sugar between 10 and 12, and
insert pies with 2 and 8 grams of sugar, in that order, between pies 12
and 6). Then, we can grab