Time limit: 1 second
Annie has two favourite baseball teams: the Swifts and the
Semaphores. She has followed them throughout the season, which is now
over. The season lasted for
For each day, Annie recorded the number of runs scored by the Swifts on that day. She also recorded this information for the Semaphores.
She would like you to determine the largest integer
For example, if the Swifts and the Semaphores have the same total
number of runs at the end of the season, then you should output
The first line of
input will contain an integer
For 7 of the 15 points available,
Output the largest integer
3
1 3 3
2 2 6
2
After 2 days, each team had scored a total of 4 runs.
3
1 2 3
4 5 6
0
The only time when the Swifts and the Semaphores had scored the same number of runs was the beginning of the season.
4
1 2 3 4
1 3 2 4
4
The Swifts and Semaphores have the same number of total runs after the first game, and after the third game, and after the fourth game. We take the largest of these values (1, 3 and 4) and output 4.
Time limit: 1 second
Joe Coder is camping near the Bay of Fundy between Nova Scotia and New Brunswick. When he arrived at the bay, he was told that the difference in height between high tide and low tide at the Bay of Fundy was the largest tidal difference in the world. Ever the skeptic, Joe decided to verify this. He chose a reference point and, after learning from the radio when the tides were highest and lowest, he went with a boat to his reference point and measured the depth of the water. Unfortunately, on the last day of his trip, a strong wind scattered his measurements.
Joe has recovered all of his measurements, but they may not be in their original order. Luckily, he remembers some things about his measurements:
He started measuring water levels at a low tide, his second measurement was of the water level at high tide, and after that the measurements continued to alternate between low and high tides.
All high tide measurements were higher than all low tide measurements.
Joe noticed that as time passed, the high tides only became higher and the low tides only became lower.
Given Joe’s measurements in no particular order, you must reconstruct the correct order in which the measurements were taken.
The first line contains the integer
Output the
8
10 50 40 7 3 110 90 2
10 40 7 50 3 90 2 110
The low tide measurements (in order) were 10, 7, 3, and 2. The high tide measurements (in order) were 40, 50, 90, and 110.
Time limit: 2 seconds
Tudor is a contestant in the Canadian Carpentry Challenge (CCC). To
win the CCC, Tudor must demonstrate his skill at nailing wood together
to make the longest fence possible using boards. To accomplish this
goal, he has
A board is made up of exactly
two pieces of wood. The length of a board made of wood with
lengths
The first line will contain the integer
The second line will contain
For 5 of the 15 available marks,
For an additional 4 of the 15 available marks,
For an additional 3 of the 15 available marks,
Output two integers on a single line separated by a single space: the length of the longest fence and the number of different heights a longest fence could have.
4
1 2 3 4
2 1
Tudor first combines the pieces of wood with lengths
5
1 10 100 1000 2000
1 10
Tudor can’t make a fence longer than length
Time limit: 3 seconds
The city of Watermoo has buildings numbered
The municipal government of Watermoo is currently operating a valid
plan of
Additionally, researchers at the University of Watermoo have
developed an experimental pipe enhancer which you can use on one pipe of
your choice. It will reduce that pipe’s cost from
The city wants you to minimize the cost of the plan, and they want you to do it quickly. Every day, the city will allow you to activate one pipe, and deactivate another pipe. How many days do you need to make the set of active pipes form a valid plan, whose cost is minimum among all valid plans and all choices of enhanced pipe?
Note that it is possible that the plan becomes invalid while you are working, but by the end it should be a valid plan.
The first line will contain the integers
It is guaranteed that there is at most one pipe connecting any two buildings and no pipe connects a building to itself.
For 3 of the 15 available marks,
For an additional 5 of the 15 available marks,
For an additional 3 of the 15 available marks,
For an additional 2 of the 15 available marks,
Output one integer on a single line, the minimum number of days to
complete this task. If the initial valid plan is already an optimal
plan, then output
4 4 0
1 2 1
2 3 2
3 4 1
4 1 1
1
Note that it does not matter which pipe you use the pipe enhancer on
because
On the first day, you should deactivate the pipe from building
5 6 2
1 2 5
2 3 5
1 4 5
4 5 5
1 3 1
1 5 1
2
One solution using the minimum number of days is to first use the
pipe enhancer on the pipe from building
Additionally, there are no solutions where you use the pipe enhancer on
the pipe from building
4 4 0
1 2 715827882
2 3 715827882
3 4 715827882
4 1 715827884
0
The initial valid plan is already an optimal plan. Be careful of integer overflow when implementing your solution.
Time limit: 5 seconds
The Rail Metro Transit (RMT) operates a very unusual subway system.
There are
RMT is conducting a load test of their system using volunteer
passengers to ride the subway trains. The test begins with one subway
train in each station and for every
Throughout the test, RMT will perform
You are RMT’s biggest fan, so you have generously volunteered to keep track of RMT’s actions and report the answers to their surveys.
The first line will contain three space-separated integers
The next
1
r
, which represents a survey (
2
For 2 of the 15 available marks,
For an additional 2 of the 15 available marks,
For an additional 3 of the 15 available marks,
For an additional 3 of the 15 available marks, there will be no more
than
For every survey, output the answer to the survey on a separate line.
5 2 5
1 2 1 2 2
1 2 3 4 5
1 1 5
2 1
1 3 5
2 2
1 1 3
15
10
9
The subway system is illustrated below, with the stations numbered from 1 to 5 and the lines connecting stations marked as either being line 1 or line 2:
3 1 7
1 1 1
114 101 109
1 1 1
2 1
1 1 1
2 1
1 1 1
2 1
1 1 1
114
109
101
114
The subway system is illustrated below, with the stations numbered from 1 to 3 and the lines connecting stations marked as all being line 1: