electicode
АсосӣКурсҳоМанбаъҳоМасъалаҳоОлимпиадаи миллӣМусобиқаҳоҶадвали роҳбарон
...

Archivist

Маҳдудияти вақт: 1000msМаҳдудияти ҳофиза: 256MB
Ҳамаи ҳалҳо

Тавсифи масъала

On an Archive Server in Earth's orbit, there are NNN modules placed in a row. Each module contains an unknown integer value: p1,p2,…,pNp_1, p_2, \ldots, p_Np1​,p2​,…,pN​.

Husanboy wants to learn all these values, but due to the security system, he cannot read the module contents directly. The server only provides the following paid service:

If Husanboy chooses iii and jjj (1≤i≤j≤N1 \le i \le j \le N1≤i≤j≤N), the server tells him the sum of the values in the interval [i,j][i, j][i,j]: pi. In return, Husanboy pays "credits".

Husanboy may make as many queries as he wants. His goal is to reconstruct all values p1,p2,…,pNp_1, p_2, \ldots, p_Np1​,p2​,…,pN​ exactly, while minimizing the total cost.

Input Format

The first line contains one positive integer NNN.

The next NNN lines describe the query costs. On line i+1i+1i+1 there are N−i+1N-i+1N−i+1 non-negative integers, in the following order: C(i,i), C(i,i+1), …, C(i,N)C(i,i),\ C(i,i+1),\ \ldots,\ C(i,N)

Constraints

1≤N≤10001 \le N \le 10001≤N≤1000

0≤C(i,j)≤1060 \le C(i,j) \le 10^60≤C(i,j)≤106 for all 1≤i≤j≤N1 \le i \le j \le N1≤i≤j≤N

Output Format

Print one integer --- the minimum total cost Husanboy must pay to determine all elements of array ppp.

Scoring

SubtaskConstraintsPoints
1N≤20N \le 20N≤2019
2N≤250N \le 250N≤25029
3No additional constraints52

Мисолҳо

Мисол 1
Вуруд
3
5 5 1
5 2
5
Баромад
8
Шарҳ

The minimum total cost is 888.

  • Pay C(1,3)=1C(1,3)=1C(1,3)=1 to learn p1+p2+p3p_1+p_2+p_3p1.

© 2026 Electicode. All rights reserved.

+pi+1+⋯+pjp_i + p_{i+1} + \cdots + p_j
pi​+pi+1​+⋯+pj​
C(i,j)C(i, j)C(i,j)
C
(
i
,
i
)
,
 
C
(
i
,
i
+
1), …, C(i,N)
​
+
p2​+
p3​
  • Pay C(2,3)=2C(2,3)=2C(2,3)=2 to learn p2+p3p_2+p_3p2​+p3​.
  • Pay C(3,3)=5C(3,3)=5C(3,3)=5 to learn p3p_3p3​.
  • Then:

    • p1=(p1+p2+p3)−(p2+p3)p_1 = (p_1+p_2+p_3)-(p_2+p_3)p1​=(p1​+p2​+p3​)−(p2​+p3​)
    • p2=(p2+p3)−p3p_2 = (p_2+p_3)-p_3p2​=(p2​+p3​)−p

    So all elements can be reconstructed exactly.

    3
    ​