NOIP '18 P1 - Paving Roads

View as PDF

Submit solution

Points: 7 (partial)
Time limit: 1.0s
Memory limit: 512M

Problem type

You have an array of length n that are initially zero. In each step, you may choose a consecutive interval [L,R] and increase the values by 1. Find the minimum number of operations required so that the i-th entry of the array is equal to di.

Input Specification

The input file has two lines. The first line has an integer n denoting the length of the array. The second line contains n integers separated by one space. The i-th integer denotes di.

Output Specification

The output contains only one integer denoting the minimum number of operations required.

Sample Input

Copy
6
4 3 2 5 3 5

Sample Output

Copy
9

Explanation

One possible optimal solution is to choose [1,6],[1,6],[1,2],[1,1],[4,6],[4,4],[4,4],[6,6],[6,6] as the subintervals to increment.

Constraints

For 30% of test data, 1n10.
For 70% of test data, 1n1000.
For 100% of test data, 1n100000, 0di10000.


Comments


  • 1
    maxcruickshanks  commented on Aug. 18, 2022, 1:22 a.m.

    Since the original data were weak, an additional test case was added, and all submissions were rejudged.


    • 1
      maxcruickshanks  commented on Aug. 18, 2022, 1:16 p.m.

      An additional test case was added again, and all submissions were rejudged.