This question refers to the problem Distance between friends made available by OBI 2019 and. subsequently, made available by the website URI Online Judge with the same title and numbering 3050 of the category AD-HOC.
Behold Here the integrity of the statement made available by the OBI and, if you prefer, see Here the integrity of the statement made available by the website URI - which by the way is the same.
To resolve this issue we must take into consideration a few things.
First of all we must capture the values correctly. The correct capture of the values is:
n = int(input())
p = [int(i) for i in input().split()]
Note that n is the amount of values that will be entered in the next input.
In the next input we should insert exactly the quantity of values specified above.
After that we must calculate the correct distance between the building and the top floor of building 0. For this we must implement the following loop:
dist = 0
k = -1
for i in range(n):
d = p[0] + i + p[i]
if d > dist:
dist = d
k = i
And finally, we must calculate the position of the friend farthest from the top floor of building K. For this we must implement another loop of repetition:
max_dist = 0
for j in range(n):
if j != k:
max_dist = max(max_dist, p[k] + abs(k - j) + p[j])
print(max_dist)
Note that in this last stage we are calculating the maximum distance between friends.
The complete code would be:
n = int(input())
p = [int(i) for i in input().split()]
dist = 0
k = -1
for i in range(n):
d = p[0] + i + p[i]
if d > dist:
dist = d
k = i
max_dist = 0
for j in range(n):
if j != k:
max_dist = max(max_dist, p[k] + abs(k - j) + p[j])
print(max_dist)
For the record, this issue has already been tested, submitted and properly approved.
Please click on [Edit] and put the code and other messages as text. Putting them as image is not ideal, understand the reasons reading the FAQ. It is also interesting to bring the statement here, because the questions can not depend on external links (they can serve as a complement, but the question must have all the necessary information)
– hkotsubo