M.A.H.M.O.O.D's blog

By M.A.H.M.O.O.D, history, 9 years ago, In English

Good morning, today I stumbled across this problem which I could not solve it looks really easy but I couldn't. I read the Tutorial but still didn't get it if you can explain this problem to me or at least give me the code to understand on my own I would be very greatful thanks in advance. the link to the problem is here

  • Vote: I like it
  • +4
  • Vote: I do not like it

»
9 years ago, # |
  Vote: I like it 0 Vote: I do not like it

"or at least give me the code to understand on my own". You can see others code :\ ! Click here then click on the blue number on the left of the submission to view the code.

»
9 years ago, # |
  Vote: I like it 0 Vote: I do not like it

simple greedy algorithm would pass . make an array with length M say it's A, A[0] is 1 and the rest are 0 . to make the smallest number with sum S iterate through the array from the right to the left (from index M-1 to 0) and keep increasing A[i] until one of this two condition become true : 1 — the sum of the numbers in A is S then you have found the smallest number with sum S and length M . 2 — A[i] become 9 : if i = 0 , then the answer is "-1 -1" else go to i — 1 to find the largest do the same algorithm but iterate from the left to the right . code

»
9 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Thanks guys.