Блог пользователя M.A.H.M.O.O.D

Автор M.A.H.M.O.O.D, история, 9 лет назад, По-английски

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

  • Проголосовать: нравится
  • +4
  • Проголосовать: не нравится

»
9 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

"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 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Thanks guys.