#abc229f. F - Make Bipartite

F - Make Bipartite

Score : 500500 points

问题描述

给定一个包含 N+1N+1 个顶点的无向图。
这些顶点依次称为 Vertex 00、Vertex 11\ldots、Vertex NN

对于每个 i=1,2,,Ni=1,2,\ldots,N,图中存在一条权重为 AiA_i 的无向边,连接 Vertex 00 和 Vertex ii

另外,对于每个 i=1,2,,Ni=1,2,\ldots,N,图中还存在一条权重为 BiB_i 的无向边,连接 Vertex ii 和 Vertex i+1i+1。(这里,Vertex N+1N+1 实际上表示 Vertex 11。)

除了上述这 2N2N 条边以外,图中没有其他边。

现在让我们从这个图中删除一些边,使得图变为二分图。
需要删除的边的最小总权重是多少?

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Given is an undirected graph with N+1N+1 vertices.
The vertices are called Vertex 00, Vertex 11, \ldots, Vertex NN.

For each i=1,2,,Ni=1,2,\ldots,N, the graph has an undirected edge with a weight of AiA_i connecting Vertex 00 and Vertex ii.

Additionally, for each i=1,2,,Ni=1,2,\ldots,N, the graph has an undirected edge with a weight of BiB_i connecting Vertex ii and Vertex i+1i+1. (Here, Vertex N+1N+1 stands for Vertex 11.)

The graph has no edge other than these 2N2N edges above.

Let us delete some of the edges from this graph so that the graph will be bipartite.
What is the minimum total weight of the edges that have to be deleted?

Constraints

  • 3N2×1053 \leq N \leq 2 \times 10^5
  • 1Ai1091 \leq A_i \leq 10^9
  • 1Bi1091 \leq B_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \dots ANA_N

B1B_1 B2B_2 \dots BNB_N

Output

Print the answer.

Sample Input 1

5
31 4 159 2 65
5 5 5 5 10

Sample Output 1

16


Deleting the edge connecting Vertices 0,20,2 (weight: 44), the edge connecting Vertices 0,40,4 (weight: 22), and the edge connecting Vertices 1,51,5 (weight: 1010) makes the graph bipartite.

Sample Input 2

4
100 100 100 1000000000
1 2 3 4

Sample Output 2

10

update @ 2024/3/10 10:01:45