Squirrel

Time limit: 0.35s Memory limit: 512MB Input: Output:

A squirrel has discovered a storage with nuts. The storage contains NN rows of rooms numbered from 00 to N1N - 1. The row with index ii contains i+1i + 1 rooms numbered from 00 to ii. The room located in the row ii and column jj contains AijA_{ij} nuts.

In the N×(N+1)2\frac{N \times (N+1)}{2} rooms, the numbers AijA_{ij} are all distinct and have values between 11 and N×(N+1)2\frac{N \times (N + 1)}{2}.

Formally, the storage has the shape of a triangle half-matrix, the one located below the main diagonal (including the main diagonal), in which each element represents a number of nuts. The numbers in this half-matrix are the numbers from 11 to N×(N+1)2\frac{N \times (N + 1)}{2}, with each number appearing exactly once.

For example, for N=5N = 5 the storage would have 1515 rooms containing the numbers from 11 to 1515. An example of such a storage could be the half-matrix shown below:

The squirrel walks along the main diagonal, and at each room located at position (i,i)(i,i) it chooses a single room located in the rectangle with the top-right corner at position (i,i)(i,i) and the bottom-left corner at position (N1,0)(N - 1,0), and eats the acorns from that room. In the example above, when the squirrel is at position (1,1)(1, 1), it may choose to eat the nuts from one of the 88 rooms colored in red. After it has gone through all the rooms on the main diagonal and has eaten the nuts from exactly NN different rooms, the squirrel leaves satisfied.

Task

Given NN and AijA_{i j} for any ii with 0i<N0 \le i < N and jj with 0ji0 \le j \le i, find the maximum number of nuts the squirrel can eat.

Also, for each of the NN rooms visited, find the number of nuts eaten by the squirrel.

Implementation

You must implement the function

void solve(int N, vector<vector<int>> A, long long& answer, vector<int>& solution)

Function parameters:

Input data:

  • int N : storage size / number of rows
  • vector<vector<int>> A : Number of nuts in each room (More precisely, in Ai,jA_{i,j} with 0i<N0 \le i < N and 0ji0 \le j \le i you will find the number of nuts in the room at position jj of row ii)

Output data:

  • long long &answer : will contain the maximum number of nuts that the squirrel can eat after going through all NN rooms of the diagonal.
  • vector<int> &solution : a vector that will contain the amount of nuts eaten by the squirrel in each room. (More precisely, solutionisolution_i with 0i<N0 \le i < N represents the number of nuts eaten by the squirrel when it is in the room (i,i)(i,i))

ATTENTION!! For both AA and solution\text{solution}, the indices start from 00 and the size of the solutionsolution vector should be exactly NN.

Constraints

  • 1N2 0001 \leq N \le 2 \ 000
  • 1AijN×(N+1)21 \leq A_{i j} \leq \frac{N \times (N + 1)}{2}
# Points Constraints
1 11 N5N \leq 5.
2 12 N100N \leq 100.
3 23 N500N \leq 500.
4 15 N1 000N \leq 1 \ 000.
5 13 N1 200N \leq 1 \ 200.
6 8 The contents of the matrix are assigned randomly.
7 18 No additional constraints.

Example

input

5
1
14 6
8 2 15
3 10 4 12
9 5 13 11 7

output

64
14 10 15 12 13

Log in or sign up to be able to send submissions!