Implementation task


Plus
Pin


Problem description Progress
ID 38282. Team Jupiter
Темы: Implementation task   

Every year in one of the corners of our universe the Intellectual Olympic Games are held. This year, the honor of hosting this large-scale event fell to the planet Jupiter. You have to select two teams for the Games from the available n candidates for the national team.

All candidates are schoolchildren, each candidate studies in a certain class. Like on Earth, Jupiter has 11 classes, numbered from 1 to 11. Two teams are selected for the Games based on the results of the qualifying competitions. There are five qualifying rounds for the competition. At the end of each round, each student can score from 0 to 300 points, the more the better.

The four best schoolchildren get into the first team according to the sum of points scored in all qualifying rounds. The top four in terms of total points from those who did not make it to the first team, and at the same time do not study in grade 11, get into the second team.

All rounds have already been held, and it turned out that any two candidates scored a different number of points in total. It remains only to write a program that, according to the available data on the candidates and the results of the rounds, will determine those eight who will defend the honor of Jupiter at the Intellectual Olympic Games and prove that Jupiter — super planet!

Input
The first line of the input contains a single number n — the number of candidates for the Jupiter team ( 8 ≤ n ≤ 500 ).

The next n lines contain information about the candidates. Each line contains 6 integers — the number of the class in which the next candidate is studying, and his results in the qualifying rounds.

The class number is a number from 1 to 11, and the result on each round — number from 0 to 300.

It is guaranteed that all participants have different total scores.

It is guaranteed that there are at least 8 candidates who are not in grade 11.

Imprint
Output two lines.

The first line must contain four space-separated integers — the numbers of the candidates who will get into Jupiter's first team. Candidates are numbered starting from one in the order they appear in the input. Numbers should be displayed in ascending order.

The second line should describe the second Jupiter command in a similar format.
 

Examples
# Input Output
1 10
9 50 271 287 282 42
10 230 241 137 14 240
10 276 109 300 197 300
8 205 292 194 232 74
10 294 291 299 300 255
9 195 275 265 134 9
11 204 259 96 263 83
7 141 223 85 84 26
11 286 294 289 221 261
10 277 52 117 272 262
3 4 5 9
1 2 6 10

ID 38623. Cake set
Темы: Combinatorial structures    Implementation task   

Wushan from the planet Blook opened a bakery. His bakery sells N kinds of cakes. Each type of cake has three parameters: "beauty", "taste" and "popularity". The 1st kind of cake has xi beauty, yi flavor and zi popularity. These values ​​can be zero or negative.
Gromozeka decided that he would buy M pieces of cake. It selects a set like this:
- You cannot use two or more pieces of the same type of cake.
- With the above condition, the set of cakes that maximizes (absolute overall beauty value) + (absolute overall taste value) + (absolute overall popularity value) is selected.
Find the maximum possible value (total beauty absolute value) + (total taste absolute value) + (total popularity absolute value) for the set of cakes Gromozeka chooses.

Input
The first line contains two space-separated integers N (1<=N<=1000) and M (0<=M<=N). The next N lines contain   three integers xi, yi and zi (-109<=xi, yi, zi <=109, 1<=i<=N).< br />
Imprint
Print the maximum possible value (absolute value of overall beauty) + (absolute value of overall taste) + (absolute value of overall popularity) for the set of cakes Gromozeka chooses.
 

 

Examples
# Input Output Explanation
1 5 3
3 1 4
1 5 9
2 6 5
3 5 8
9 7 9
56 Think about the 2nd, 4th and 5th types of cakes. The overall beauty, taste and popularity will be as follows:
Beauty: 1 + 3 + 9 = 13
Taste: 5 + 5 + 7 = 17
Popularity: 9 + 8 + 9 = 26
The value (absolute value of overall beauty) + (absolute value of overall palatability) + (absolute value of overall popularity) here is 13 + 17 + 26 = 56. This is the maximum value.
2 5 3
1-2 3
-4 5 -6
7-8-9
-10 11 -12
13-14 15
54 Consider having 1st, 3rd and 5th types of cakes. The overall beauty, taste and popularity will be as follows:

Beauty: 1 + 7 + 13 = 21
Taste: (−2) + (- 8) + (- 14) = - 24
Popularity: 3 + (- 9) + 15 = 9
The value (absolute value of overall beauty) + (absolute value of overall palatability) + (absolute value of overall popularity) here is 21 + 24 + 9 = 54. This is the maximum value.
3 10 5
10-80 21
23 8 38
-94 28 11
-26 -2 18
-69 72 79
-26 -86 -54
-72 -50 59
21 65 -32
40 -94 87
-62 18 82
638 If we have 3rd, 4th, 5th, 7th and 10th kinds of cakes, the overall beauty, taste and popularity will be -323, 66 and 249 respectively.
The value of (total beauty absolute value) + (total palatability absolute value) + (total popularity absolute value) here is 323 + 66 + 249 = 638. This is the maximum value.
4 3 2
2000000000 -9000000000 4000000000
7000000000 -5000000000 3000000000
6000000000 -1000000000 8000000000
30000000000 The beauty, flavor, and popularity values ​​of the cakes, as well as the value to be printed, may not correspond to 32-bit integers.

 

ID 38873. Room
Темы: Implementation task   

The room is characterized by three integers: length, width and height, given in millimeters. A room is considered good if the following conditions are met:
the ratio of the smallest of the length and width to the height is at least 2, as well as the ratio of the largest of the length and width to the smallest does not exceed 2.
Based on the dimensions of the room, determine if it is a good one.

Input
The input is three integers: w, l and h — length, width and height of the room, each
on a separate line (1000 ≤ w, l, h ≤ 10,000).

Imprint
If the room is good, print "good", otherwise print "bad".
 

Examples
# Input Output
1 4000
6000
3000
bad
2 4600
8600
1600
good

ID 39062. broken printer
Темы: Cycles    Implementation task   

A broken color printer, printing numbers, paints all enclosed areas red.  For example, the numbers 04, 6, 9 have one closed area.  In the figure 8 - 2 closed areas.  In other numbers, there are no closed areas that are painted over. There are h closed areas remaining in the red printer for painting.  Find the minimum non-negative number that will print out the red ink in the printer. The number must not contain leading zeros.  If the printer is out of red ink, it cannot print a closed area number.


Input
The input is a number h (0 <= h <= 510).

Imprint
Output the number to be printed.
 
Examples
# Input Output
1 15 48888888
2 70 8888888888888888888888888888888888

ID 39388. Contact tracing
Темы: Implementation task    Simulation tasks   

Farmer John continues to take care of the health of his cows, consecutively numbered 1…N.
Recently, the FD checked them all and found out that some of them are sick. Using video from the barn, the FD can find out which pairs of cows interacted to spread the disease. The FD has collected a list indicating the time at which the interaction of pairs of cows in the video (t,x,y) took place, meaning that at time t cow x interacted with cow y. The FD also knows the following:

  1.  Exactly one cow was initially infected (patient zero).
  2.  Once a cow is infected, she passes the infection on to her next K interactions (possibly involving the same partner multiple times). After K times of transmission, she stops transmitting the infection (on realizing that she is infecting, she begins to thoroughly wash her hooves).
  3.  Once she gets sick, she stays sick.

Unfortunately, the PD doesn't know which of his N cows is "Patient Zero", and he doesn't know the value of K!. Help him narrow down the ranges of these unknowns based on his data. The answer is guaranteed to exist.

Input
The first input line contains N (2≤N≤100) and T (1≤T≤250). The next line contains a string of length N, consisting of 0 and 1, describing the current state of N FD cows, 0 - healthy, 1 - sick. Each of the following T lines describes an entry from the list of FD interactions, and consists of three numbers, t, x, y, where t is a positive integer interaction time (t≤250), x and y are different integers in the interval 1…N,, indicating which cows interacted at time T. No more than one interaction occurs at one time T.
Imprint
Print one line containing three integers x, y, z, where x is the number of different cows that could be "patient zero" y - the smallest possible value of K that fits the input data z - the largest possible value of K that fits the input data If there is no upper bound for K, print "Infinity"; for z. Note that K=0 is possible.
Examples
# Input Output
1 4 3
1100
7 1 2
5 2 3
6 2 4
1 1 Infinity

ID 39397. Gromozeka and Alice - 2
Темы: Implementation task    One-Dimensional Arrays    Cycles   

Alice and Gromozeka went for a walk around the city. Entering the first cafe, Alice looked at her watch and remembered the time of entry. Further, she memorized only the number of minutes that she and Gromozeka spent between two cafes visited (from entering one cafe to entering another). At the end of the walk, Alice decided to restore the chronology - the time of entering the next cafe.
Write a program that will determine at what time Alice and Gromozeka went to the next cafe. 

Input
The first line specifies the moment of time at which Gromozeka and Alice entered the first cafe. Time format: hours (a number from 00 to 23), followed by a colon, then minutes (a number from 00 to 59). The time string is written without spaces.
The second line contains a natural number N (2 <= N <= 1000) - the number of visited cafes (including the cafe from which they left at the initial moment of time and the last cafe). The third line contains N-1 number: the first one shows the time in minutes from the entrance to the first cafe to the entrance to the second one, the second - the time from the entrance to the second cafe to the entrance to the third one, and so on. Each of these numbers is natural and does not exceed 1000.

Imprint
Print for each cafe the entry time of Alice and Gromozeka. The time format must be the same as in the input data.
 

Examples
# Input Output
1 07:00
4
10 5 3
07:00
07:10
07:15
07:18

ID 27222. Where's Bessie?
Темы: Depth walk    Bust    Implementation task   

Farmer John is testing a new camera that can "grab the picture" and automatically calculate the position of the cows. Unfortunately, the camera does not have a very good algorithm for finding cows and the FD needs your help.
The picture taken by the camera can be described by a lattice of NxN characters, each in the range A…Z, representing one of 26 possible different colors. The FD considers the following cow recognition algorithm to be the best: PCL (possible placement of a cow) is a rectangle on a lattice (possibly the entire lattice) with sides parallel to the sides of the lattice, which does not contain other PCLs inside and has the following property: exactly two colors must be present inside this rectangle, one forms a continuous region and the other forms two or more continuous regions.
 
For example, this image
 
AAAAA
ABABA
AAABB
is PCL because the A characters form a contiguous region, the B characters form more than one contiguous region. The interpretation is a cow with color A and spots with color B.
 
A region is continuous if you can traverse the entire region by moving from one cell to another neighboring one in the directions up, down, left, right.
 
Based on the given image of the PD camera, determine the amount of PCL.
 
INPUT FORMAT:
 
The first line of input contains N, the size of the grid (1≤N≤20). The next N lines describe the image, each consisting of N characters.
 
OUTPUT FORMAT:
 
Amount of PCL in the image.
 
Input Output
4
ABBC
BBBC
AABB
ABBC
2

ID 43349. Secret Sequence
Темы: "Two Pointers"    One-Dimensional Arrays    Implementation task   

Alice left a secret sequence a[1..n] for her father Professor Seleznev. In order not to hide it, she decided to write it in the most visible place, but in a different order of numbers. Professor Seleznev knows that Alice rewrote the secret sequence as follows:

  • the first number on the left is the number a1;
  •  the first number on the right is the number a2;
  • the second number from the left (after a1) is the number a3;
  • the second number from the right (that is, before the number a2) is the number a4;
  • all other numbers are written in the same way.

That is, if the secret sequence was a = [1, 2, 3, 4, 5, 6], then the professor would see the following sequence [1, 3, 5 , 6, 4, 2]. Professor Seleznev was in a great hurry and only managed to save the sequence he saw into the computer. Write a program that will show the professor the original secret sequence.



Input
The first line contains the size of the sequence n (1 <= n <= 300) written by Alice for her father. The second line contains n numbers ai (1 <= ai < ;= 109) - the sequence itself.

Imprint
Print the original sequence that Alice wrote out for her father.
 
 
Examples
# Input Output
1

6
1 3 5 6 4 2

1 2 3 4 5 6
2 1
23
23

 

ID 43351. Tommy's books
Темы: "Two Pointers"    Binary search    Implementation task   

Tommy loves to read. He took n books from the library (in the ith book ai pages, pages are numbered with < code>1). Tommy is very careful with books, so he wrapped each of them in a cover. But, since he did not have any transparent covers, he numbered the books from 1 to n and wrote the number on the cover of each book.

Tommy has been reading for m days in a row. He reads books strictly in order, starting with book number 1.  Every day, he writes down on the board the total number of pages he has read so far.

For example, if Tommy took 2 books and, at the same time, there were 3 pages in the first book, and 5 pages in the second, then after reading 2 pages on the first day, and 4 pages on the second day, Tommy had on the board two numbers 2 and 6 would be written.

Tommy took a short break, and when he returned to reading, he realized that he had forgotten which book he was reading and which page he had stopped on. He also does not want to lose statistics, but wants to correct it by adding on what day which book he read and on which page he stopped. Help Tommy, by the numbers written on the board, to determine on what day what book he read and on what page he stopped.


Input
The program receives several lines as input. The first line contains two integers n and m (1 <= n, n <= 2·105) - the number of books Tommy borrowed from the library and the number of days that Tommy read books. The second line contains the sequence a1, a2, ... an (1 <= a1<= 1010), where ai equals the number of pages in the ith book. The third line contains the sequence d1, d2, ... dm (1 <= dj <= a+ a+...+ an), where dj equals the total number of pages read by Tommy by jth day. All dj are in in ascending order.

Output

Output m lines. In each line print two numbers - нbook number k (1 <=  <= n) and page number in this book s (1 <= <= ak) that Tommy settled on for the current day.

 
Examples
# Input Output
1 3 6
10 15 12
1 9 12 13 15 17
1 1
19
2 2
23
25
27
2 2 3
5 10000000000
5 6 9999999999
1 5
2 1
29999999994

ID 43474. Gromozeka and valerian
Темы: for loop    Cycles    Simple puzzles    Implementation task   

Gromozeka loves valerian very much. On his home planet Chumaroza you can buy for k chumriks (local currency) the first package of valerian, for 2·k chumriks -  the second and so on (in other words, ith packing you have to pay i·k chumrikov). Gromozek wants to buy  w packages of valerian.  He has n chumriks. How many chumriks will he have to take on credit from the chumaroz bank in order to buy w packages of valerian?


Input

The first line contains three positive integers k, n, w (1  <=  k, w< /code>  <=  1000, 0 <= n <= 109) , the cost of the first package, Gromozeka's initial number of chumaroziki and the number of packages of valerian he wants to buy.


Output

Print a single integer - the number of chumaroziks that Gromozeka needs to borrow from the bank. If you don't need to take a loan, print 0.

 
Examples
# Input Output
1 3 17 4 13

ID 43532. Books off the shelf
Темы: One-Dimensional Arrays    Implementation task   

Peter has an extensive library of books. Now he stands near the shelf with adventure stories. It contains n books. All books on Petya's shelf are always numbered from left to right. Book number i has ai pages. On the shelf, next to which Petya is now standing, the number of pages in each book is different.

The peculiarity of the shelves in Petya's library is such that he can only take the last book from the shelf (that is, either the leftmost or the rightmost).

Petya is leaving for the holidays with his grandmother and wants to take two books with him, the thickest and the thinnest. Help Petya find out what is the minimum number of books he needs to remove from the shelf before he gets the two books he needs. Please note that Petya also removes the thickest and thinnest books from the shelf, so they are also considered. 

 

Input
The first line contains a single integer n (2 <= n <= 100) - the number of books on the shelf.  The second line contains n different integers a1, a2, ..., an (1 <= ai  <= 106) - number of pages in the book.

 

Imprint
Print a single integer — the minimum number of books Petya needs to remove from the shelf.

 
Examples
# Input Output
1
5
1 5 4 3 2
2
2
8
2 1 3 4 5 6 8 7
4

ID 43718. Misha's Cubes
Темы: Using sort    Greedy Algorithm    Implementation task    Simple puzzles    "Two Pointers"   

Little Misha has cubes, each of which has one English lowercase letter written on it. Yesterday he laid out the cubes in two rows. In the first row Misha has n cubes with letters, in the second - m cubes with letters. It so happened that in these two rows there are no matching letters. In other words, no letter is contained in both rows at the same time.
Today little Misha decided to continue playing with blocks. But now he takes any one cube from any row and makes a third row of them, always adding a cube to the end. Little Misha never takes more than k dice in a row from the same row. Misha stopped playing when he ran out of cubes in one row (in the first or in the second).
Dad, who was watching the game, noticed that playing in this way, Misha got the lexicographically smallest line. Using the known two strings, which are formed by reading the letters of the first and second rows and the number k determine the string that little Misha received.

The string x is lexicographically less than the string y only and only if one of the following conditions is true:
- x is a prefix of y, but x != y;
- in the first position, where x and y differ, in the string x there is a letter that is in the alphabet earlier than the corresponding letter y.


Input
The program receives several lines as input. The first line contains three numbers: n - the number of cubes in the first row, m - the number of cubes in the second row, k > is an integer(1 <= n, m, k <= 100). The second line contains a string a of length n - a string formed by reading the letters written on the cubes of the first row. In the third line - string b of length m - a string formed by reading the letters written on the cubes of the second row.

Imprint
Print the answer to the problem.
 
 

Examples
# Input Output
1 6 4 2
aaaaaa
bbbb
aabaabaa