Type: Default 1000ms 256MiB

加加加加到厌倦

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

Description

给两个长度为 nn 的数组 aabb ,你可以执行以下操作,任意选定 lr,(1lrn)l,r,(1 \leq l \leq r \leq n) ,将该区间内的 aia_i 全部加 11 ,问最少经过多少次操作能将 aa 数组变成 bb 数组,如果无法实现则输出 1-1

Input

第一行输入 n(1n106)n(1 \leq n \leq 10^6)

第二行输入nn个数,表示数组 a(1ai109)a(1 \leq a_i \leq 10^9)

第三行输入nn个数,表示数组 b(1bi109)b(1 \leq b_i \leq 10^9)

Output

输出最小操作数。

Samples

5
5 2 7 2 3
6 4 8 9 10
8
6
1 1 4 5 1 4
1 2 6 2 8 2
-1

Limitation

Time Limit: 1 second

Memory Limit: 256MiB

SDNU_ACM_ICPC_2025新生月赛

Not Attended
Status
Done
Rule
ACM/ICPC
Problem
13
Start at
2025-11-16 12:00
End at
2025-11-16 17:00
Duration
5 hour(s)
Host
Partic.
38