You are not logged in. Please login at www.codechef.com to post your questions!

×

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.

This question is marked "community wiki".

asked 18 Mar '14, 20:29

shangjingbo's gravatar image

3★shangjingbo ♦♦
161446375
accept rate: 0%

wikified 18 Mar '14, 21:10

kunal361's gravatar image

4★kunal361
6.0k133272

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).

(21 Mar '14, 14:51) gursheel072★

@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)

link
This answer is marked "community wiki".

answered 04 Dec '14, 21:23

subhankar_raj's gravatar image

2★subhankar_raj
12
accept rate: 0%

Weak test cases mate

link

answered 30 Oct '15, 01:06

chathur's gravatar image

0★chathur
1
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×15,679
×1,652
×944
×20

question asked: 18 Mar '14, 20:29

question was seen: 5,160 times

last updated: 17 May '18, 03:37