Logo
(追記) (追記ここまで)

31145번 - Wiring Engineering 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
8 초 1024 MB21150.000%

문제

On the north side of Bytestreet, there are $n$ buildings standing sequentially one next to the other, labeled by 1,2,ドル\dots,n$ from east to west. The coordinate of the $i$-th building is $(i,1)$.

On the south side of Bytestreet, there are $n$ communication towers standing sequentially one next to the other, labeled by 1,2,ドル\dots,n$ from east to west. The coordinate of the $i$-th tower is $(i,-1)$.

You are an electrical engineer in Byteland, your job is to design a wiring scheme. A wire can be used to connect a building and a tower. Each connection runs along a straight line. For each pair of building and tower, you can connect at most one wire between them. When you use a wire to connect the $i$-th building with the $j$-th tower, you will get $w_{i,j}$ dollars from the owner of the building, and the wire can be regarded as a segment connecting $(i,1)$ and $(j,-1)$.

Each building can be connected with multiple wires, but you need to pay $u_i$ dollars if you want to connect at least one wire to the $i$-th building, because you should first install equipment in that place. For the same reason, each tower can be connected with multiple wires, but you also need to pay $v_i$ dollars if you want to connect at least one wire to the $i$-th tower. What is more, two wires can only intersect at their endpoints, in order to prevent short-circuit.

Unfortunately, it is impossible to install equipment in some places, so they can not be connected with any wire. You will be given $q$ queries, in the $i$-th query, you will be given four integers $a_i,b_i,c_i$ and $d_i,ドル which means you can only install equipment in buildings whose label is in $[a_i,b_i],ドル and you can only install equipment in towers whose label is in $[c_i,d_i]$. Your task is to find a wiring scheme to make money optimally. Note that the answer can't be negative because you can choose to do nothing.

입력

The input contains only a single case.

The first line of the input contains two integers $n$ and $q$ (1ドル \leq n\leq 500,ドル 1ドル\leq q \leq 300,000円$), denoting the number of buildings (or towers) and the number of queries.

The second line contains $n$ integers $u_1,u_2,\dots,u_n$ (1ドル\leq u_i\leq 10,000円$), denoting the cost to install equipment in each building.

The third line contains $n$ integers $v_1,v_2,\dots,v_n$ (1ドル\leq v_i\leq 10,000円$), denoting the cost to install equipment in each tower.

In the next $n$ lines, the $i$-th line $(1 \le i \le n)$ contains $n$ integers $w_{i,1},w_{i,2},\dots,w_{i,n}$ (1ドル\le w_{i,j}\leq 10,000円$), describing how much money you can get if you connect the $i$-th building with the $j$-th tower.

In the next $q$ lines, the $i$-th line $(1 \le i \le q)$ contains four integers $a_i,b_i,c_i$ and $d_i$ (1ドル\leq a_i\leq b_i\leq n,ドル 1ドル\leq c_i\leq d_i\leq n$), describing the $i$-th query.

출력

For each query, print a single line containing an integer, denoting the maximum amount of dollars you can earn.

제한

예제 입력 1

3 4
1 2 1
2 1 2
1 2 3
4 5 6
3 2 1
1 3 1 3
2 3 1 2
1 1 2 3
1 2 2 3

예제 출력 1

8
5
1
7

힌트

출처

Contest > Open Cup > 2021/2022 Season > Stage 6: Grand Prix of EDG L번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /