[Huawei OD test questions] Street lighting (java) 100% pass rate [2023 (B volume) 100 points]

street lighting

topic description

N street lights are installed on a straight road,
starting from position 0, and the distance between street lights is fixed at 100 meters.
Each street light has its own lighting radius.
Please calculate the distance between the first street light and the last street light, which
cannot be illuminated . The length of the interval and .

enter description

The first line is a number N, indicating the number of street lights, 1 <= N <= 100000 The
second line is a number separated by N spaces, indicating the lighting radius of the street light, 1 <= lighting radius

output description

The sum of the lengths of the intervals that cannot be illuminated.

example one

enter

2
50 50

output

0

illustrate

Streetlight 1 covers 0-50 Streetlight 2 covers 50-100
Streetlight 1 and Streetlight 2 (0-100 meters) There is no uncovered section

Reference Problem Solving Java

import 

Guess you like

Origin blog.csdn.net/weixin_45541762/article/details/132394859