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

×

CRANBROM - Editorial

Level: Medium

Concepts: Greedy,Dynamic programming, hashing

Problem link: http://www.codechef.com/CRNM2014/problems/CRANBROM

This one can be done in many ways. Here is an O(n) solution .

Below I will outline a way where we dynamically store whatever best so far we could have earned every time we find a broom.

Whenever we have a customer we will compare the current profit with the one will be making if we sell the broom being demanded.

Pseudocode:

//initialise an array l with -1 ans=0
for every day iterate: string,i=input();//take the input if string=='found': l[i]=ans else if l[i]>=0: ans=max(ans,l[i]+i) l[i]=-1 print ans

This question is marked "community wiki".

asked 11 Feb '14, 04:07

apoorv_j's gravatar image

2★apoorv_j
1158
accept rate: 0%

edited 12 Feb '14, 03:20

admin's gravatar image

0★admin ♦♦
19.8k350498541

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,852
×2,657
×2,212
×7

question asked: 11 Feb '14, 04:07

question was seen: 1,066 times

last updated: 12 Feb '14, 03:20