第一届湖北省赛F. Flower Road
F. Flower Road
Once upon a time, there was a beautiful princess named TQM, and a handsome prince named GSS. One day, the prince would like to visit the princess. While in front of the princess' house, there was a flower-beds with blooming flowers. The prince was supposed to go through the flower-beds choosing the best ``Flower Road''.
Here is the task. The flower-beds is presented by a matrix with integers on each grid representing the princess' satisfaction of the flowers on it. Now, the prince was on the top left point (1, 1) and the princess was on the bottom right point (N, N). While the princess didn't want this to be so easy, she operated M times ``rotation'' on the flower-beds according to the order. Each time, she would choose a
matrix whose top left point was
. Then, four disjoint parts of the matrix whose length of size was
rotated clockwise. Here is an example to make the ``rotation'' clearly.
Then, your task is to help the prince to choose a best ``Flower Road'' after these operations with the largest sum of the satisfaction. By the way, the prince will take the shortest way, which means he will only go down (from point (x, y) to point (x+1, y)) and right (from point (x, y) to point (x, y+1)).
输入描述:
The first line of input contains two integers, N () and M (), indicating the numbers N and M described above. Then N lines follow, and each line N integers, representing the matrix. Then M lines follow, each line has three integers , where xi and yi are coordinates of the top right point of i-th rotation matrix, th - side length of the matrix.
输出描述:
Output the max sum of the satisfaction.