P13544 [OOI 2022] Serious Business
Description
Dima is taking part in a show organized by his friend Peter, the show is called . In this show Dima is required to cross a $3 \times n$ rectangular field, consisting of $3$ rows and $n$ columns. Each row has its cells indexed from $1$ to $n$, from left to right.
Each cell of the filed contains an integer $a_{i,j}$. Initially Dima's score equals zero, and whenever Dima reaches a cell in row $i$ and column $j$, his score changes by $a_{i,j}$. Note that, the score might become negative.
Initially all cells in the first and in the third row are marked as available, and all cells in the second row are marked as unavailable. However, Peter offered Dima some help: there are $q$ special offers in the show, $i$-th special offer allows Dima to mark cells in the second row between $l_i$ and $r_i$, though Dima's score changes by $k_i$ whenever he accepts the special offer. Dima is allowed to use as many special offers as he pleases, and might mark the same cell as available multiple times.
Dima starts his journey in the first row and in the first column and would like to reach the cell in the third row and in the last column. He can move either down to the next row or right to the next column (meaning he could increase the current row or column by 1), thus making $n+1$ moves in total, out of which $n-1$ would be horizontal and $2$ --- vertical.
Peter promised Dima to pay him based on his final score, so the sum of all numbers of all visited cells minus the cost of all special offers used. Please help Dima to maximize his final score.
Input Format
The first input line contains two integers $n$ and $q$ ($1 \le n, q \le 500\,000$) --- the number of columns in the field and the number of special offers.
The next three lines describe the field, $i$-th of them contains $n$ integers $a_{i1}$, $a_{i2}$, $\ldots$, $a_{in}$ ($-10^9 \le a_{ij} \le 10^9)$ --- the values in the $i$-th row.
The next $q$ lines describe special offers: $i$-th offer is described by 3 integers $l_i$, $r_i$ and $k_i$ ($1 \leq l_i \leq r_i \leq n$, $1\leq k_i\leq 10^9$) --- the segment that is being unblocked and the cost of this special offer.
Output Format
Output one integer --- the maximum final score Dima can achieve.
Explanation/Hint
### Scoring
The testset for this problem consists of 6 test groups. You get points for a group only if your solution passes all tests from this group and from all the required groups. $\textbf{Offline-evaluation}$ means that you will not get immediate feedback for this group and you will be able to see the outcome only after the end of the competition. Please note that it is not required to pass all sample test cases.
| Group | Points | Additional constraints | < | Required groups | Comment |
|:-----:|:------:|:----------------------:|:-:|:---------------:|:-------:|
| | | $n$ | $q$ | | |
| 0 | $0$ | -- | -- | -- | Sample test cases. |
| 1 | $10$ | -- | $q=1$ | -- | |
| 2 | $16$ | $n \leq 500$ | $q \leq 500$ | $0$ | |
| 3 | $14$ | $n \leq 2\,000$ | $q \leq 5\,000$ | $0, 2$ | |
| 4 | $17$ | -- | -- | -- | All $k_i$ are equal |
| 5 | $21$ | $n \leq 100\,000$ | $q \leq 100\,000$ | $0, 2, 3$ | |
| 6 | $22$ | -- | -- | $0$--$5$ | **Offline-evaluation.** |