CF1648D.Serious Business

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Dima is taking part in a show organized by his friend Peter. In this show Dima is required to cross a 3×n3 \times n rectangular field. Rows are numbered from 11 to 33 and columns are numbered from 11 to nn .

The cell in the intersection of the ii -th row and the jj -th column of the field contains an integer ai,ja_{i,j} . Initially Dima's score equals zero, and whenever Dima reaches a cell in the row ii and the column jj , his score changes by ai,ja_{i,j} . Note that the score can become negative.

Initially all cells in the first and 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 qq special offers in the show, the ii -th special offer allows Dima to mark cells in the second row between lil_i and rir_i as available, though Dima's score reduces by kik_i whenever he accepts a special offer. Dima is allowed to use as many special offers as he wants, and might mark the same cell as available multiple times.

Dima starts his journey in the cell (1,1)(1, 1) and would like to reach the cell (3,n)(3, n) . 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+1n + 1 moves in total, out of which exactly n1n - 1 would be horizontal and 22 would be 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.

输入格式

The first input line contains two integers nn and qq ( 1n,q5000001 \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, ii -th of them contains nn integers ai1a_{i1} , ai2a_{i2} , ..., aina_{in} ( 109aij109)-10^9 \le a_{ij} \le 10^9) — the values in the ii -th row.

The next qq lines describe special offers: the ii -th offer is described by 3 integers lil_i , rir_i and kik_i ( 1lirin1 \leq l_i \leq r_i \leq n , 1ki1091\leq k_i\leq 10^9 ) — the segment that becomes unblocked and the cost of this special offer.

输出格式

Output one integer — the maximum final score Dima can achieve.

输入输出样例

  • 输入#1

    4 3
    1 0 2 -1
    -3 1 9 2
    3 2 4 1
    1 2 5
    2 3 4
    1 4 14

    输出#1

    13
  • 输入#2

    5 4
    -20 -10 -11 -10 1
    1 3 3 6 3
    14 -20 3 6 2
    1 5 13
    1 2 2
    3 5 3
    2 3 1

    输出#2

    -4

说明/提示

In the first example, it is optimal to use Peter's second offer of 44 rubles and go through the cells (1,1)(1, 1) , (1,2)(1, 2) , (1,3)(1, 3) , (2,3)(2, 3) , (3,3)(3, 3) , (3,4)(3, 4) , earning 1+0+2+9+4+14=131 + 0 + 2 + 9 + 4 + 1 - 4 = 13 rubles in total.

In the second example, it is optimal to use Peter's second and third offers of 22 and 33 rubles, respectively, and go through the cells (1,1)(1, 1) , (2,1)(2, 1) , (2,2)(2, 2) , (2,3)(2, 3) , (2,4)(2, 4) , (3,4)(3, 4) , (3,5)(3, 5) , earning 20+1+3+3+6+6+223=4-20 + 1 + 3 + 3 + 6 + 6 + 2 - 2 - 3= -4 rubles.

首页