0% found this document useful (0 votes)
50 views18 pages

Problem A. A String Challenge: Input

The problem describes a game where points in 3D space are given, and cubes of side length 2K can be created around each point. The volume of the union of these cubes is calculated. Input consists of the number of test cases T, then for each case the number of points N and cube size K, followed by the coordinates of each point. The output is the total volume of the union of cubes for each test case.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views18 pages

Problem A. A String Challenge: Input

The problem describes a game where points in 3D space are given, and cubes of side length 2K can be created around each point. The volume of the union of these cubes is calculated. Input consists of the number of test cases T, then for each case the number of points N and cube size K, followed by the coordinates of each point. The output is the total volume of the union of cubes for each test case.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

ICPC BOLIVIA 2019 September 28th, 2019

Problem A. A String Challenge


Source file name: challenge.c, challenge.cpp, challenge.java, challenge.py
Input: Standard
Output: Standard
Author(s): Juan Pablo Marin Rosas - Cignuz - Mexico

John really likes string challenges; he is so excited to challenge you to solve the one he solved last night. In
this challenge, you have a string S containing only lowercase characters (from a to z), and a list of “replace
patterns” is defined. A replace pattern is a string associated to a character. You can produce a new string
by replacing all occurrences of each character with the “replace pattern” associated to the character, for
example, if you have the string “aaaaaaa” and the replace pattern “a => bc” you can form the string
“bcbcbcbcbcbcbc”. If a character does not have a “replace pattern” associated then the character is not
modified in the string, for example, if you have the string “aabc” and the replace patterns “a => bc,
b=>a“ but no replace pattern for the character “c”, then the produced string will be: “bcbcac”.
It was easy for you to replace the string with John’s rules, he is mad, he wants to see you fail, that is why
he hardened the challenge, this time, you need to replace the string N times, this is, after applying all
“replace patterns” in string S you get the string S1 , then produce a new string from S1 using the same
“replace patterns” to get S2 , and so on until you get SN . Can you find what will be the length of the
string SN ?.

Input
The first line of input contains a single integer T (1 ≤ T ≤ 100) the number of test cases. Each test
case starts with a line containing a string S (1 ≤ |S| ≤ 106 ) and the numbers K (1 ≤ K ≤ 26) and N
(1 ≤ N ≤ 1010 ) separated by space, representing the initial string to be replaced, the number of patterns
in the list and the number of times the replace patterns should be applied. The next K lines in the test
case contain a character C and a string PC (1 ≤ |PC | ≤ 103 ) separated by a space, representing that PC
is the "replace pattern" for character C. It is guaranteed that a character has at most one replace pattern
associated.

Output
For each test case print a line containing the length of the string after applying the replace patterns N
times as stated in the description. Since this number can be very large print it modulo 109 + 7.

Example
Input Output
3 14
aaaaaaa 1 1 2
a bc 12
a 1 10000
a bc
a 3 3
a abc
b c
c ba
Use fast I/O methods

www.facebook.com/RedProgramacionCompetitiva Twitter: @RedProgramacion


Page 1 of 18
Competitive Programming Network - 10th Activity September 28th, 2019

Problem B. Bags
Source file name: plasticbag.c, plasticbag.cpp, plasticbag.java, plasticbag.py
Input: Standard
Output: Standard
Author(s): Jose Carlos Laura Ramirez - New Vision Data - Bolivia

Every day we use plastic bags to buy things and to discard things. We tend to think they are for
granted with no consequences. Sadly that is not the case, every time we use a plastic bag, whether it
is biodegradable or not, we are polluting our environment, each plastic bag can take up to 100 years to
decompose.
In the country of Nlognia the government decided to, from now on (know as the day 1), charge a $1 tax
for each plastic bag that each person used. Nlognia government has a complete registry of in which day
and how many plastic bags each person have used.
Government system must process all the registries to compute the total amount of tax each person must
pay. Unfortunately, the registries takes time to be uploaded to the system and are not sorted in any way.
This represents a problem to Nlognia people, because they would like to know the total tax they are being
charged between day F and day T , but the system may have registries that have not yet processed by
the time this is requested
Eddy is the chief from the tax government agency, and he decide that the system should respond the
queries that people have with the data that has been already processed, but without warning people that
the information is still incomplete. Also, he wants the system to respond to queries that can help him
to decide the best way to arrange the bags usage registries, for this, he would like to know how many
different ways the plastic bags usage registries already uploaded to the system can be arranged.
Since you are the best programmer they found, they want you to help Nlognia.
To simplify this problem, let’s consider only one person plastic bags usage, and also consider that the
numbers of ways that bags can be combined will be asked for all the days.

Input
The first line contain the number of test cases (no more than 15). The first line of each test case contains
two integers (1 ≤ N ≤ 105 ) and (1 ≤ M ≤ 105 ), representing the number of days that has been passed
since day 1, and the number of events that the computer should process respectively.
The next M lines are the events that the system should process, there are three types of events.

• If the lines starts with a Q there will be two integers F and T (1 ≤ F ≤ T ≤ N ) in the same line.
This type of event is a query, meaning that the system should print how much tax is accumulated
between day F and day T .
• If the lines starts with a W it is a query for the numbers of ways to arrange the bags usage registries.
For example, if the currents bags are 5, 3, 6 then there are six different ways to arrange them: 3, 5, 6,
3, 6, 5, 5, 3, 6, 5, 6, 3, 6, 3, 5, 6, 5, 3. But if the registries already uploaded are 5, 3, 3 there are only
three different ways to arrange them: 3, 3, 5, 3, 5, 3, 5, 3, 3. Since this number can be very big, the
system should print the reminder after dividing it by 4300000013.
• If the lines starts with a U there will be two integers (1 ≤ D ≤ N ) and (1 ≤ B ≤ 104 ) in the same
line. This type of event is a bag usage registry upload, and means that at day D, B plastic bags
were used. Note that multiple records of plastic bag usage can exist for the same day D.

Output
Print one line for each query of type Q and W , the line should contain a single integer, being the answer

www.redprogramacioncompetitiva.com/ Twitter: @RedProgramacion


Page 2 of 18
ICPC BOLIVIA 2019 September 28th, 2019

for the query as stated above. Queries should be answered in the order they appear.

Example
Input Output
1 1
10 14 0
U 5 7 7
W 3
Q 1 4 9
Q 5 10 10
U 1 2 3
U 8 2 18
W 6
Q 4 10
U 5 1
Q 4 10
W
U 6 8
Q 5 10
W
Use fast I/O methods

www.facebook.com/RedProgramacionCompetitiva Twitter: @RedProgramacion


Page 3 of 18
Competitive Programming Network - 10th Activity September 28th, 2019

Problem C. Cubic Games in the Space


Source file name: cubicgames.c, cubicgames.cpp, cubicgames.java, cubicgames.py
Input: Standard
Output: Standard
Author(s): Eddy Cael Mamani Canaviri - Vizonomy - Bolivia

Ailin is playing with a Virtual Reality device, the game is called the Interstellar Competition of Physics
Challenge (aka ICPC). In the final stage she successfully won the level, and the game let her play a special
stage in order to pay the efforts invested in the previous levels.
The game starts with N points in a the 3-dimensional space. For each point in the set, you can create
a cube from a point increasing the dimensions of it by an integer K. More formally if you have a point
xi , yi , zi then you can get a perfect cube with the coordinates:

A : (xi − K, yi − K, zi − K)
B : (xi − K, yi − K, zi + K)
C : (xi − K, yi + K, zi − K)
D : (xi − K, yi + K, zi + K)
E : (xi + K, yi − K, zi − K)
F : (xi + K, yi − K, zi + K)
G : (xi + K, yi + K, zi − K)
H : (xi + K, yi + K, zi + K)

Ailin wants to know what is the volume of the union from the N cubes formed after increase the volume
by the value K.

Input
The input file starts with a line containing an integer number T , representing the number of test cases
T (T ≤ 10). T test cases follow, each test case starts with a line containing two integer numbers N and
K, each of the following N lines in the test case contains the coordinates of each point xi , yi , zi . You can
assume that 1 ≤ N ≤ 1000, |xi |, |yi | ≤ 5 ∗ 104 , 1 ≤ K ≤ 4 ∗ 104

Output
For each case, print what is the volume asked before.

Example
Input Output
3 216
1 3 16
-1 2 -1 12
2 1
5 5 5
7 5 5
2 1
5 5 5
6 5 5
Use fast I/O methods

www.redprogramacioncompetitiva.com/ Twitter: @RedProgramacion


Page 4 of 18
ICPC BOLIVIA 2019 September 28th, 2019

This is the graphic for the first sample.

www.facebook.com/RedProgramacionCompetitiva Twitter: @RedProgramacion


Page 5 of 18
Competitive Programming Network - 10th Activity September 28th, 2019

Problem D. Dimitrov and the Triangular Spiral


Source file name: spiral.c, spiral.cpp, spiral.java, spiral.py
Input: standard
Output: standard
Author(s): Hugo Humberto Morales Peña - UTP & RPC - Colombia

Recently the professor Humbertov Dimitrov was sick, he had a fever and when he went to bed, he began
to have a delirious dream. In the dream he draw over and over again a triangular spiral that began in
the origin of the cartesian plane (coordinate (0, 0)) and the triangular spiral got bigger every time linking
integer coordinates in the cartesian plane. For clarity, the triangular spiral is presented below:

The dream was so disturbing and it was repeated so many times, that when Dimitrov woke up, he
remembered perfectly the triangular spiral, and for this reason he drew the previous graphic.
In the dream Dimitrov was disturbed and intrigued because he didn’t know if all the integer coordinates
could be reached at some point in the triangular spiral and, if that was the case, he also didn’t know what
the n movement would be to reach a specific point on the Cartesian plane when drawing the triangular
spiral. The first doubt was immediately resolved when the professor did the graphic ... all the points
(integer coordinates) of the Cartesian plane are eventually reached by the triangular spirals!
Now the professor Dimitrov needs your help to indicate the movement n that reaches a specific point on
the Cartesian plane when drawing the triangular spiral.

Input
Input begins with an integer t (1 ≤ t ≤ 5 × 105 ), the number of test cases, followed by t lines, each line
contains two integers separated by a space, denoting the coordinates x and y in the Cartesian coordinate
system (−108 ≤ x, y ≤ 108 ).

Output
For each test case, you should print a single line containing an integer, denoting the n movement that
reaches the point of the (x, y) coordinates in the Cartesian plane.

www.redprogramacioncompetitiva.com/ Twitter: @RedProgramacion


Page 6 of 18
ICPC BOLIVIA 2019 September 28th, 2019

Example
Input Output
15 1
0 0 2
-1 0 3
0 1 4
1 0 5
2 -1 6
1 -1 7
0 -1 8
-1 -1 9
-2 -1 10
-3 -1 11
-2 0 12
-1 1 13
0 2 14
1 1 15
2 0
Use fast I/O methods

www.facebook.com/RedProgramacionCompetitiva Twitter: @RedProgramacion


Page 7 of 18
Competitive Programming Network - 10th Activity September 28th, 2019

Problem E. Expecting to Win at the Casino


Source file name: casino.c, casino.cpp, casino.java, casino.py
Input: Standard
Output: Standard
Author(s): Juan Pablo Marin Rosas - Cignuz - Mexico

Santiago is lost at the casino looking for a game to play where he can ensure he will not lose a lot of
money. After looking to several game tables, he found a game that sounds promising.
The game is a two player game, the casino and a person, it is played in a table with N squares drawn in
a straight line, players take turns and in each turn the player will choose one or two adjacent squares not
chosen by any of the players before and put one coin over each of the selected squares. The game ends
when there are no more squares to choose, the winner is the player who put the last coin, the price, all
the coins in the table.
Santiago believes he can win a lot of money in this game; given the number of squares in the table and
the player who plays first and knowing both players will play optimally, can you determine if Santiago
can win the game?

Input
The first line contains a single integer number T (1 ≤ T ≤ 105 ) the number of test cases. Each of
the following T lines describe a test case, each line contains two numbers separated by a space: N
(3 ≤ N ≤ 109 ) and P (0 ≤ P ≤ 1), the number of squares in the table, and the player who plays first
respectively, if P=0 then Santiago plays first, if P=1 then the casino plays first.

Output
For each test case print a line containing a single integer number, being 1 if Santiago can win the game,
0 otherwise.

Example
Input Output
3 0
1 1 1
2 0 0
3 1
Use fast I/O methods

www.redprogramacioncompetitiva.com/ Twitter: @RedProgramacion


Page 8 of 18
ICPC BOLIVIA 2019 September 28th, 2019

Problem F. Fractions
Source file name: fraction.c, fraction.cpp, fraction.java, fraction.py
Input: Standard
Output: Standard
Author(s): Jorge Teran - UMSA - Bolivia

A continuous fraction is an expression obtained through an iterative process of representing a number as


the sum of its integer part and the reciprocal of another number.
The division of two integers exemplifies this process. The division gives as a result two values: the quotient
(k) and the reminder (r). Given a, and b we have:

a r
=k+
b b
The reminder r can be written as:

r 1
=
b b
r
the quotient and reminder of b/r, which is called k1 , r1 , and the quotient and the reminder of k1 /r1 that
we call k2 , r2 respectively, iteratively repeating this process we have:
a 1
=k+
b 1
k1 + 1
k2 1
k3 +
k4 + 1
r4
The list of quotients is called the continuous fraction of a/b and is represented by [k; k1 , k2 , k3 , . . . , ].
Eddy is working on this task and he is very tired, he asked you for help to write a program that given
a real number R as input computes the first 8 elements of the continuous fraction and the fraction a/b
that approximates R. For example the first 8 continued fractions of 1.54312 are 1, 1, 1, 5, 3, 2, 1, 3. And
the fraction is 662/429.

Input
The first line of the input is N (1 < N < 100) a integer representing the number of test cases. Each of
the next N lines contains a real number R (1 < R < 100) with at most seven decimal places.

Output
For each test case print two lines, the first line should contain 8 numbers separated by a space representing
the first 8 numbers of the continued fraction. The second line should contain the fraction a/b that
approximates R. It is guaranteed that the input numbers have at least 8 values for the continuous
fraction.

Example
Input Output
2 1 1 1 5 3 2 1 3
1.54312 662/429
3.14159 3 7 15 1 25 1 7 4
314159/100000
Use fast I/O methods

www.facebook.com/RedProgramacionCompetitiva Twitter: @RedProgramacion


Page 9 of 18
Competitive Programming Network - 10th Activity September 28th, 2019

Problem G. Goblins
Source file name: goblins.c, goblins.cpp, goblins.java, goblins.py
Input: Standard
Output: Standard
Author(s): Eddy Cael Mamani Canaviri - Vizonomy - Bolivia

Ailin was playing with her toys all day, in the night while she was sleeping suddenly she started dreaming
with goblins (because her father plays a lot a game called Clash of Wars and there are a lot of goblins in
the game).
She noticed that the village of goblins is being terrorizing by the Dark King, so once a week, the King
comes to the village, and put the goblins in a row and then put some stickers in their nape, each sticker
has a color in the range [1..C].
The i-th goblin (Gi ) can see the sticker on the j-the goblin (Gj ) for all j < i, so the first goblin can not
see the sticker from any goblin, the second can see the sticker in the nape of the first goblin, the third
can see the stickers from the first and the second goblin, and so on.
Now the kills start! The Dark King starts from Gn , and asks: ’What is the color of your sticker?’. If the
goblin tells the right color, the goblin can preserve his life, otherwise, the goblin will die! Note that the
last goblin can see all the N − 1 napes and their colors. After that, the King asks the same question to
Gn−1 , and then to Gn−2 and so on. Each goblin speaks only when the Dark King asks for his color. Note
that all the goblins can hear all the answers.
The goblins are smart, and in order to minimize the amount of kills, they use a secret strategy that allow
them to preserve the maximum amount of goblins.
Can you find what is the probability to keep exactly G goblins after K weeks the Dark King visits the
village? You can assume that G ≤ N .
Print the answer using the values a, b separated by a single space, where a and b are integers for the
value a/b, note that a ≤ b holds, and also GCD(a, b) = 1 holds. As the response can be too large, both
numbers will be taken modulo 3038000027.

Input
The first line of input contains a single number T , representing the number of test cases. Each of the
following T lines describes a test case containing the numbers N , K, C and G, representing the number
of goblins in the village, the number of weeks the Dark King will come, the number of different colors of
the stickers the Dark King will put in the napes, and the number of goblins to preserve, respectively .
1 ≤ T ≤ 222, 1 ≤ N ≤ 20000, 1 ≤ K ≤ 20000, 1 ≤ C ≤ 20.

Output
For each test case, print a line with two numbers a, and b separated by a single space, where a and b are
the integers such that the probability P = a/b, note that a ≤ b holds, and also GCD(a, b) = 1 holds. As
these can be too large, print them modulo 3038000027. If the answer is an integer number X, then print
X followed by a space and then the 1, i.e: "X 1".

Example
Input Output
3 1 2
1 1 2 1 1 2
1 1 2 0 4 9
7 2 3 6
Use fast I/O methods

www.redprogramacioncompetitiva.com/ Twitter: @RedProgramacion


Page 10 of 18
ICPC BOLIVIA 2019 September 28th, 2019

In the first case the goblin can only guess his color, so the possibility to keep exactly 1 goblin is 1/2. And
the possibility to have zero goblins is also 1/2 (second test case).

www.facebook.com/RedProgramacionCompetitiva Twitter: @RedProgramacion


Page 11 of 18
Competitive Programming Network - 10th Activity September 28th, 2019

Problem H. How Many Subsets?


Source file name: subsets.c, subsets.cpp, subsets.java, subsets.py
Input: standard
Output: standard
Author(s): Hugo Humberto Morales Peña - UTP & RPC - Colombia

We have a set A of positive integers with cardinality N (|A| = N , remember that the cardinality of a set
is the total of different elements it has). You want to find out how many subsets of size two have a sum
of their elements less than or equal to S.
For example, if you have the following set A = {6, 5, 1, 4, 2, 3} and S = 7, then there is a total of 9
subsets of size two whose sum of its elements is less than or equal to 7, said subsets are: {6, 1}, {5, 1},
{5, 2}, {1, 4}, {1, 2}, {1, 3}, {4, 2}, {4, 3} and {2, 3}.
Your mission, if you decide to accept it, is to count the total of subsets of size two that have a sum of
their elements less than or equal to S.

Input
The input of the problem consists of a single test case. The test case contains three lines, the first
line contains two positive integer numbers N (1 ≤ N ≤ 106 ) and Q (1 ≤ Q ≤ 102 ), which represent
respectively the cardinality of the set A and the total of queries that will be made on the set A. The next
line contains exactly N space-separated positive integer numbers A1 , A2 , A3 , . . ., AN (1 ≤ Ai ≤ 108 ,
for 1 ≤ i ≤ N ), it is obviously guaranteed that the N elements of the set A are different. The next line
contains exactly Q space-separated positive integer numbers S1 , S2 , S3 , . . ., SQ (1 ≤ Sj ≤ 2 × 108 , for
1 ≤ j ≤ Q), for the queries.

Output
Your program should print Q lines, each of them containing a single value that represents the total result
of subsets of size two that the sum of their elements is less or equal to S.

Example
Input Output
6 3 9
6 5 1 4 2 3 11
7 8 12 15
Use fast I/O methods

www.redprogramacioncompetitiva.com/ Twitter: @RedProgramacion


Page 12 of 18
ICPC BOLIVIA 2019 September 28th, 2019

Problem I. Isabel’s numbers


Source file name: isabel.c, isabel.cpp, isabel.java, isabel.py
Input: Standard
Output: Standard
Author(s): Juan Pablo Marin Rosas - Cignuz - Mexico

Isabel is obsessed with numbers, this time he is representing numbers using N wood sticks. As Isabel
is very smart, he already created a method to represent the numbers. In his method, he uses the same
amount of sticks to represent the same digits every time:

• 7 sticks to represent the digit 8.

• 6 sticks to represent digits: 0, 6, and 9.

• 5 sticks to represent digits: 2, 3, and 5.

• 4 sticks to represent digits: 4, and 7.

• 2 sticks to represent digit: 1.

Using this method, he can represent the numbers knowing beforehand the amount of wood sticks he needs.
Isabel knows he can not represent all the numbers, the amount of wood sticks he owns is limited, and
therefore, he can not represent numbers that require more wood sticks than the amount he owns. As
obsessed he is with numbers, he is representing the positive numbers starting with the number 1, then
the number 2, then the 3, and so on, until he gets to the number K, which is the first number that can
not be represented using Isabel’s method with the amount of wood sticks he owns. Can you help Isabel
to find this number faster?

Input
The first line of the input contains an integer T (1 ≤ T ≤ 50), representing the number of test cases in the
input. Each of the following T lines contains a single integer N (1 ≤ N ≤ 128), representing the number
of wood sticks Isabel owns.

Output
For each test case in the input, print a line with an integer indicating the smallest positive integer number
that cannot be represented using Isabel’s method.

Example
Input Output
4 2
2 1
1 10
7 20
9
Use fast I/O methods

www.facebook.com/RedProgramacionCompetitiva Twitter: @RedProgramacion


Page 13 of 18
Competitive Programming Network - 10th Activity September 28th, 2019

Problem J. Judging Connect Four


Source file name: connectfour.c, connectfour.cpp, connectfour.java, connectfour.py
Input: Standard
Output: Standard
Author(s): Juan Pablo Marin Rosas - Cignuz - Mexico

Connect Four, is a two-player connection game in which the players first choose a color and then take
turns dropping one colored disc from the top into a seven-column, six-row vertically suspended grid. The
pieces fall straight down, occupying the lowest available space within the column. The game ends when a
player wins by placing at least four of his/her stones consecutively in at least one line, either horizontally,
vertically, or diagonally, or in a draw if the board is completely filled without anyone winning. After a
game ends, the players are not allowed to drop more stones onto the board.
The connect four contest committee know of your amazing programming skills, so they have asked you
to write an automatic connect four judge system, this judge system will have has input a representation
of the connect four board and should determine one of the following results:

• The game have ended, in which case, the judge should also notify who the winner is.

• The game should continue, in which case, the judge should also notify who is the next player to
move.

• The board is an invalid game. This is, there is no way to get the provided board if the rules of the
game are followed.

Input
The first line of the input contains an integer T (1 ≤ T ≤ 100), representing the number of test cases in
the input. Each of the following T test cases are described with 6 lines each containing 7 characters, a ’.’
if that position is not occupied in the board, ’Y’ if the position is occupied by a disc of the first player,
’R’ if the position is occupied by a disc of the second player. Test cases are separated by blank line.

Output
For each test case in the input print the judging result:

• If the board is an invalid game print a line with the value -1.

• If the game has ended print in a line the value 0 a space and a value 0 if it’s a draw, 1 if player 1
won, 2 if player 2 won.

• If the game should continue print a single line with the value 1 a space and the number 1 if player
1 is the next to move, or 2 if player 2 is the next to move

www.redprogramacioncompetitiva.com/ Twitter: @RedProgramacion


Page 14 of 18
ICPC BOLIVIA 2019 September 28th, 2019

Example
Input Output
6 1 1
....... 1 2
....... 0 1
....... 0 2
....... 0 0
....... -1
.......

.......
.......
.......
.......
.......
.YRY...

.......
.......
Y......
Y......
YR.....
YRR....

.......
.......
R......
YR.....
YYR....
YRYR...

RRYRYRY
YYYRYRR
RYYRRYR
YRRYYRR
YYYRRYY
YRRYYRR

..Y....
.......
.......
.......
..Y....
..R....
Use fast I/O methods

www.facebook.com/RedProgramacionCompetitiva Twitter: @RedProgramacion


Page 15 of 18
Competitive Programming Network - 10th Activity September 28th, 2019

Problem K. Keep the Oil but Sell!


Source file name: plane.c, plane.cpp, plane.java, plane.py
Input: Standard
Output: Standard
Author(s): Eddy Cael Mamani Canaviri - Vizonomy - Bolivia

Eddy has an old friend that has an old land with crude oil. He begins to tell his story:
Once upon a time I discovered this well and I started to connect some pipes from the well to the main tank
in order to store the oil. First there was a single sequence of pipes, but after time, I started to buy more
pipes and connect them in a way that no pair of pipes overlap, in this way it is easier for me to avoid
the oil from burning by friction between the pipes. I left the land a couple years ago, and the last time I
went to it I have noticed that thieves have robbed some pipes, they were smart, I wouldn’t notice if I didn’t
inspect all the land, they made sure that every pipe is connected with at least another pipe. I am not mad
about the thieves robbing, they did what they know to do, but I would be mad if I preserve this big land for
my own at this age. .
As the oil in this land is his only source of income, he would like to preserve the amount of oil that gets
to the main tank located in the rightmost point of the land from the well located in the leftmost point
of the land, selling the most area he can from the north, this is, he is willing to cut the land horizontally
at some integer point dividing the land in two parts: north, and south, and sell the north land. Can you
help the old friend to find what is the maximum area he can sell?

Input
The first line of input contains an integer T (1 ≤ T ≤ 20), representing the number of test cases. Each
test case starts with a line containing the numbers N (1 ≤ N ≤ 104 ), M (1 ≤ M ≤ 3 ∗ 104 ), representing
the number of points and pipes, respectively. The next line in the test case contains 2 ∗ N numbers
x0 , y0 , x1 , y1 , ... (0 ≤ xi , yi ≤ 109 ) representing the coordinates of the N points. The last M lines of the
test case describe the pipes. Each line contains three integers a, b, c separated by a space representing
a pipe that joins point a and b and transport c (0 ≤ a, b < N , 0 ≤ c ≤ 109 ) units of oil. The point
represented by the coordinate x0 , y0 (first point in the input) is where the well is located. The point at
coordinate xN −1 , yN −1 (last point in the input) is where the main tank of oil is located.

Output
For each test case print in the input print a single line containing two integer numbers F and A separated
by a space, representing the amount of oil that can get to the main tank of oil from the well, and the
maximum area the old friend can sell...

Example
Input Output
1 2 60
6 7
0 3 9 6 7 6 1 9 9 5 10 2
0 5 2
0 2 10
1 4 6
2 3 8
1 3 6
1 5 0
2 4 10
Use fast I/O methods

www.redprogramacioncompetitiva.com/ Twitter: @RedProgramacion


Page 16 of 18
ICPC BOLIVIA 2019 September 28th, 2019

The original land has walls in X = 0, X = 10, Y = 0 and Y = 9. Please note that the pipes above the
red line can not increase the current flow, so we can sell an area of 60 and the flow is the same.

www.facebook.com/RedProgramacionCompetitiva Twitter: @RedProgramacion


Page 17 of 18
Competitive Programming Network - 10th Activity September 28th, 2019

Problem L. Little Password


Source file name: password.c, password.cpp, password.java, password.py
Input: Standard
Output: Standard
Author(s): Eddy Cael Mamani Canaviri - Vizonomy - Bolivia

Ailin is playing with strings, and also with substrings... Now she needs to get a special substring to use
in her passwords... She has a master string that she built some time ago. Now, the task is so easy: get
the shortest string that is not a substring in the master string!

Input
The input file starts with a line containing an integer number T , representing the number of test cases
T (T ≤ 100). T test cases follow, each test case is described with two lines, the first line of the test case
contains an integer number N , the length of the master string. The second and last line of each test case
contains the master string S . You can assume that 1 ≤ |S| ≤ 100000. All the characters used will be
digits.

Output
For each test case print the length of the string that is the shortest string that is not a substring in S, a
space, and the string itself. In case of tie, print the lexicographically smaller.

Example
Input Output
1 2 00
10
1234567890
Use fast I/O methods

www.redprogramacioncompetitiva.com/ Twitter: @RedProgramacion


Page 18 of 18

You might also like