eolymp
bolt
Try our new interface for solving problems
Məsələlər

Adding up Triangles

Adding up Triangles

Take a look at the triangle on the left of the figure below. It is made of \textbf{9} (unit) triangles arranged in three rows (\textbf{N} = \textbf{3}). Needless to say, a unit triangle is a triangle with \textbf{N} = \textbf{1}. \includegraphics{https://static.e-olymp.com/content/a1/a19617aa4b69f8460b3d541e30b679607544efeb.jpg} If you study the figure for few seconds, you'll realize that you can find \textbf{13} different triangles (which we'll call sub-triangles.) Of these \textbf{13} sub-triangles we have: Nine unit triangle; three with \textbf{N} = \textbf{2}, and one with \textbf{N} = \textbf{3}. The following table lists the number of sub-triangles in arrangements with \textbf{N} < \textbf{5}. \includegraphics{https://static.e-olymp.com/content/79/79acbecdb7f6b3733857688bb318dad0456169f6.jpg} Let's define the value of a unit triangle to be the integer value written in that triangle. In general, the value of a triangle is the sum of values in all its unit triangles. The triangle on the right is the same as the other one but with the sub-triangle having the largest value being highlighted. Write a program to determine the sub-triangle with the largest value. \InputFile Your program will be tested on one or more test cases. Each test case is specified in a single line made of integers (separated by spaces.) The first integer is the number of rows in the test case, and the remaining integers are the values of the unit triangles specified in a top-down, left-to-right order. (the first test case in the example below is the same as the one in the figure.) The last line of the input file contains the number 0 (which is not part of the test cases.) The maximum number of rows is \textbf{400}. The absolute value of a unit triangle is less than \textbf{1000}. \OutputFile For each test case, print the result using the following format: \textbf{k. V} where \textbf{k} is the test case number (starting at \textbf{1},) is a single space, and \textbf{V} is the maximum value of a sub-triangle in that test case.
Zaman məhdudiyyəti 4 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
3 6 -24 0 12 -10 12 40 -4 6
4 1 1 -1 1 1 -1 1 -1 1 1 -1 1 -1 1 -1 1
0
Çıxış verilənləri #1
1. 54
2. 4