Serious Business

시간 제한3초메모리 제한1024 MB

요약
3 x n 격자에서 2행의 구간을 여는 제안을 사서 점수를 최대로 만드는 경로를 찾는다.
난이도

어려움10점 중 8점

유형
동적 계획법, 누적 합, 그리디
정답자
아직 제출이 없습니다

문제

Dima is taking part in a show organized by his friend Peter, the show is called <<Peter helps his fellow bro to get a job>>. In this show Dima is required to cross a 3×n3 \times n rectangular field, consisting of 33 rows and nn columns. Each row has its cells indexed from 11 to nn, from left to right.

Each cell of the filed contains an integer a_i,ja\_{i,j}. Initially Dima's score equals zero, and whenever Dima reaches a cell in row ii and column jj, his score changes by a_i,ja\_{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 qq special offers in the show, ii-th special offer allows Dima to mark cells in the second row between l_il\_i and r_ir\_i, though Dima's score changes by k_ik\_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+1n+1 moves in total, out of which n−1n-1 would be horizontal and 22 --- 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 (1≤n,q≤500,0001 \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 a_i1a\_{i1}, a_i2a\_{i2}, …\ldots, a_ina\_{in} (−109≤a_ij≤109)-10^9 \le a\_{ij} \le 10^9) --- the values in the ii-th row.

The next qq lines describe special offers: ii-th offer is described by 3 integers l_il\_i, r_ir\_i and k_ik\_i (1≤l_i≤r_i≤n1 \leq l\_i \leq r\_i \leq n, 1≤k_i≤1091\leq k\_i\leq 10^9) --- the segment that is being unblocked and the cost of this special offer.

출력

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

예제2

  1. 예제 1

    입력
    4 3
    1 0 2 -1
    -3 1 9 2
    3 2 4 1
    1 2 5
    2 3 4
    1 4 14
    
    예상 출력
    13
    
  2. 예제 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
    
    예상 출력
    -4