×

# CRANBROM - Editorial

 0 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 2★apoorv_j 1●1●5●8 accept rate: 0% 0★admin ♦♦ 19.8k●350●498●541
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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