Walk - Editorial

PROBLEM LINK:

Practice
Contest

Author: Dmytro Berezin
Tester: Mahbubul Hasan
Editorialist: Jingbo Shang

DIFFICULTY:

Cakewalk

PREREQUISITES:

Programming

PROBLEM:

Given a sequence of numbers W[0…N-1], find out a number S, such that S - i >= W[i] holds for all 0 <= i < N.

EXPLANATION:

It is easy to find out the choice of decreasing speed is to decrease it by 1 after each segment. So we can have the above problem.

After some transformations, the requirement is that S >= W[i] + i holds for all 0 <= i < N. Therefore, simply let S be the maximum of W[i]+i is the best choice.

AUTHOR’S AND TESTER’S SOLUTIONS:

Author’s solution can be found here.
Tester’s solution can be found here.

3 Likes

@gursheel07 Initially I too thought it should be max(W[i])+i but that is not correct, take an example W[] = 4, 2, 1, 2 according to your approach answer should be 4, but then when chef reaches the last segment speed will be 1, which is less than 2, therefore it is not correct. The required speed for last segment is 2, hence answer would be 5. So you have to consider max(W[i]+i)

8 Likes

Weak test cases mate

Shouldn’t it be max(W[i])+i instead of max(W[i]+i)?
My answer is wrong but I couldn’t understand why it should be max(W[i]+i).

suppose we have a situation like 3,3,3,3,3 ,according to the formula max(w*)+i ,the output is 3 (3+0) but the value disappers after one step that is it will 2 for second (3) ,which is not a desired one

Why submission cannot be made to this problem

#include <bits/stdc++.h>
using namespace std;

int main() {
int t;
cin>>t;
while(t–)
{
long long int n,p;
cin>>n;
int a[n];
for(long long int i=0;i<n;i++)
cin>>a[i];
for(int i=0;i<n;i++)
{
sort(a,a+n,greater());
}
for(long long int i=0;i<n;i++)
{
p=a[0];
}
if(p==n)
printf("%d\n",p);
else if(p>n)
printf("%d\n",p);
else if(p<n)
printf("%d\n",n);
}
}

Why my submission is getting wa

I am not able to understand why it’s max(W[i],i) not max(W[i]) +i , since we can pass the shop with maximum attractiveness it can pass also other shops and we add i since velocity decrease after each segment.