1.000s
125MB
小紫是一名道路工程师,负责铺设一条长度为 lns="http://www.w3.org/1998/Math/MathML">nn 的道路。
铺设道路的主要工作是填平下陷的地表。整段道路可以看作是 lns="http://www.w3.org/1998/Math/MathML">nn 块首尾相连的区域,一开始,第 lns="http://www.w3.org/1998/Math/MathML">ii 块区域下陷的深度为 lns="http://www.w3.org/1998/Math/MathML">d_idi 。
小紫每天可以选择一段连续区间 lns="http://www.w3.org/1998/Math/MathML">[L,R][L,R] ,填充这段区间中的每块区域,让其下陷深度减少 lns="http://www.w3.org/1998/Math/MathML">11。在选择区间时,需要保证,区间内的每块区域在填充前下陷深度均不为 lns="http://www.w3.org/1998/Math/MathML">00 。
小紫希望你能帮他设计一种方案,可以在最短的时间内将整段道路的下陷深度都变为 lns="http://www.w3.org/1998/Math/MathML">00
6 4 3 2 5 3 5
9
【样例解释】
一种可行的最佳方案是,依次选择: lns="http://www.w3.org/1998/Math/MathML">[1,6][1,6]、lns="http://www.w3.org/1998/Math/MathML">[1,6][1,6]、lns="http://www.w3.org/1998/Math/MathML">[1,2][1,2]、lns="http://www.w3.org/1998/Math/MathML">[1,1][1,1]、lns="http://www.w3.org/1998/Math/MathML">[4,6][4,6]、lns="http://www.w3.org/1998/Math/MathML">[4,4][4,4]、lns="http://www.w3.org/1998/Math/MathML">[4,4][4,4]、lns="http://www.w3.org/1998/Math/MathML">[6,6][6,6]、lns="http://www.w3.org/1998/Math/MathML">[6,6][6,6]。
【数据规模与约定】
对于 lns="http://www.w3.org/1998/Math/MathML">30\%30% 的数据,lns="http://www.w3.org/1998/Math/MathML">1 ≤ n ≤ 101≤n≤10 ; 对于 lns="http://www.w3.org/1998/Math/MathML">70\%70% 的数据,lns="http://www.w3.org/1998/Math/MathML">1 ≤ n ≤ 10001≤n≤1000 ; 对于 lns="http://www.w3.org/1998/Math/MathML">100\%100% 的数据,lns="http://www.w3.org/1998/Math/MathML">1 ≤ n ≤ 100000 , 0 ≤ d_i ≤ 100001≤n≤100000,0≤di≤10000 。