#P6648. [CCC 2019] Triangle: The Data Structure
[CCC 2019] Triangle: The Data Structure
Background
In Shuchong’s parallel universe, the most important data structure in computer science is the triangle.
Note: Since the original dataset package was too large, this problem removed some testdata. The removed test points are:
- Subtask 1: 1 ~ 10
- Subtask 2: 1 ~ 10
So the test points included in this problem are:
- Subtask 1: 11 ~ 26
- Subtask 2: 11 ~ 24
If you want to test the missing test points, please go to here.
Problem Description
A triangle of size consists of rows, and row contains elements.
Also, these rows must be arranged in the shape of an equilateral triangle.
For example, the following is a triangle with .

Each triangle also contains sub-triangles.
For example, the triangle above contains:
- triangles of size .
- triangles of size .
- triangles of size .
Note that each triangle is also a sub-triangle of itself.
Now you are given a triangle of size . For every sub-triangle of size , find the sum of the maximum value among the numbers inside that sub-triangle.
Input Format
The first line contains two integers , representing the size of the triangle and the required size of the sub-triangles.
The next lines describe the triangle: line contains integers.
Output Format
Output one integer: the sum, over all sub-triangles of size , of the maximum value inside each sub-triangle.
4 2
3
1 2
4 2 1
6 1 4 2
23
Hint
Constraints
- Subtask 1 (25 pts): .
- Subtask 2 (75 pts): no special constraints.
For of the data, , and each number in the triangle .
Notes
Translated from CCC 2019 Senior T5 Triangle: The Data Structure.
Translator: @一只书虫仔.
Translated by ChatGPT 5