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

23108번 - Find the MST for Grid 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB242120100.000%

문제

Consider a grid graph: the vertices are lined up into a grid of $H$ rows by $W$ columns. Let us denote the vertex in the $i$-th row and $j$-th column as $(i, j)$.

To define the weights of the graph edges, we will consider four non-decreasing sequences, $A,ドル $B,ドル $C,ドル and $D,ドル consisting of $H-1,ドル $W,ドル $H,ドル and $W-1$ positive integers, respectively:

  • there is a bidirectional edge connecting vertices $(i, j)$ and $(i+1, j)$ of weight $A_i + B_j$ for all $i$ and $j$ such that 1ドル \le i \le H-1$ and 1ドル \le j \le W$;
  • there is a bidirectional edge connecting vertices $(i, j)$ and $(i, j+1)$ of weight $C_i + D_j$ for all $i$ and $j$ such that 1ドル \le i \le H$ and 1ドル \le j \le W-1$;
  • the graph contains no other edges.

Find the total weight of the edges in the minimal spanning tree of this graph.

입력

The first line of input contains two positive integers $H$ and $W$ (2ドル \le H, W \le 10^5$).

The second line contains $H-1$ integers $A_i$: the elements of the sequence $A$.

The third line contains $W$ integers $B_i$: the elements of the sequence $B$.

The fourth line contains $H$ integers $C_i$: the elements of the sequence $C$.

The fifth line contains $W-1$ integers $D_i$: the elements of the sequence $D$.

It is guaranteed that $A_{i-1} \le A_{i},ドル $B_{i-1} \le B_{i},ドル $C_{i-1} \le C_{i},ドル and $D_{i-1} \le D_{i}$ for $i>1,ドル and additionally, 1ドル \le A_i, B_i, C_i, D_i \le 10^6$.

출력

Print the total weight of the edges in the minimal spanning tree of the given graph. Note that the answer may not fit into a 32-bit integer.

제한

예제 입력 1

2 3
1
1 3 6
1 4
1 2

예제 출력 1

17

예제 입력 2

4 3
1 13 15
3 6 11
3 6 6 11
9 17

예제 출력 2

173

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2021 > Day 1: Kyoto U Contest 1 F번

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

출처

대학교 대회

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

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