#LX0024. [ICPC2024 Xi'an I] Make Them Straight

[ICPC2024 Xi'an I] Make Them Straight

中文翻译:

有一个长度为nn的非负整数序列a(0ai106)a(0\leq a_i\leq 10^6),你可以花费bib_i的代价把aia_i改成任意非负整数。

问:最少多少的代价可以把aa数组修改成从左到右,公差在[0,106][0,10^6]的等差数列。

n2×105n\leq 2\times 10^5

题目描述

There is a sequence aa of non-negative integers of length nn, the ii-th element of it is ai(1in)a_i(1\leq i\leq n).

A sequence is defined as 'good' if and only if there exists a non negative integer k(0k106)k(0\leq k\leq 10^6) that satisfies the following condition:

ai=a1+(i1)ka_{i}=a_{1}+(i-1)k for all 1in1\leq i\leq n.

To make this sequence 'good', for each i(1in)i(1\leq i\leq n), you can do nothing, or pay bib_i coin to replace aia_i with any non-negative integer.

The question is, what is the minimum cost to make this sequence 'good'.

输入格式

The first line contains an integer n(1n2×105)n(1\leq n\leq 2\times 10^5), described in the statement.

The second line contains nn integers a1,...,an(0ai106)a_1,...,a_n(0\leq a_i\leq 10^6).

The third line contains nn integers b1,...,bn(0bi106)b_1,...,b_n(0\leq b_i\leq 10^6).

输出格式

One integer, the answer.

5
1 4 3 2 5
1 1 1 1 1
2
5
1 4 3 2 5
1 9 1 1 1
3