#C2298. Maximum Grid Value After Operations

    ID: 45598 Type: Default 1000ms 256MiB

Maximum Grid Value After Operations

Maximum Grid Value After Operations

You are given an \(n \times n\) grid, initially filled with zeros. You will perform \(q\) operations on this grid. In each operation, you are provided with four integers \(x, y, d,\) and \(k\). The operation means that you should add the value \(k\) to each cell in the subgrid whose top-left corner is at \((x, y)\) and whose bottom-right corner is at \((\min(n, x+d-1), \min(n, y+d-1))\). After executing all operations, your task is to find the maximum value present in the grid.

Input Format: The first line contains two integers \(n\) and \(q\) separated by a space. Each of the next \(q\) lines contains four space-separated integers \(x, y, d, k\) describing an operation.

Output Format: Output a single integer representing the maximum value found in the grid after applying all operations.

inputFormat

The input is read from standard input (stdin) and is formatted as follows:

  • The first line contains two integers \(n\) and \(q\), where \(n\) is the size of the grid and \(q\) is the number of operations.
  • Then \(q\) lines follow. Each line contains four integers \(x, y, d, k\) separated by spaces, where:
    • \(x, y\): the 1-indexed coordinates of the top-left cell of the subgrid.
    • \(d\): the dimension of the subgrid (it extends \(d\) rows and \(d\) columns from \((x,y)\)).
    • \(k\): the value to be added to each cell in the subgrid.

outputFormat

The output is written to standard output (stdout) and should be a single integer representing the maximum value in the grid after all operations have been applied.

## sample
5 3
1 1 3 5
2 2 2 10
3 3 3 2
17