COI '10 #5 Lovci

View as PDF

Submit solution


Points: 35 (partial)
Time limit: 1.0s
Memory limit: 64M

Problem types

Mirko drew a 2N by 2N chessboard and decided to play the following game:

On each square, he inscribed an integer denoting the value of that square. In the middle of the first row (columns N and N+1), he placed two bishops. Mirko now calculates the lines of sight of the two bishops: these are squares on the same diagonal as one of the bishops, but not on the square covered by any of the bishops.

For instance, if N = 3, the squares within the line of sight of the two bishops (denoted by X) at their starting positions (denoted by L) are as follows:

OOLLOO
OXXXXO
XXOOXX
XOOOOX
OOOOOO
OOOOOO

In a limited number of moves, Mirko tries to gain the maximum score by the following strategy:

  1. Before making any moves, Mirko calculates the sum of the values on squares within the lines of sight of the two bishops. That is Mirko's initial score.
  2. On each turn, Mirko chooses one of the bishops and moves it to a square within its line of sight.
  3. In its new position, the bishop can now see new squares. The sum of those squares, previously unseen by any of the bishops from the start of the game, is now added to Mirko's score.

Write a program which calculates the maximum score that Mirko can achieve in K turns.

Input Specification

The first line of input contains two integers N, K (1 \le N \le 10, 0 \le K \le 100), the dimension of the chessboard and the number of turns.

The following 2N lines contain the values of the squares in the corresponding row, 2N values per row. Those values are integers from range -1\,000\,000 to 1\,000\,000, inclusive.

Output Specification

In a single line of output, print the maximum score that Mirko can achieve.

Scoring

In test cases worth a total of 40\% points, K \le 5.

Sample Input 1

2 0
0 -9 -9 0
0 1 1 0
1 0 0 1
0 0 6 0

Sample Output 1

4

Sample Input 2

2 1
0 -9 -9 0
0 1 1 0
1 0 0 1
0 0 6 0

Sample Output 2

1

Comments

There are no comments at the moment.