When submitting a solution in C++, please select either C++14 (GCC 6-32) or C++17 (GCC 7-32) as your compiler. ×

Hadras's blog

By Hadras, history, 22 months ago, In English

Can this problem be solved using Binary Search

Link: https://codeforces.com/problemset/problem/1606/C

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

| Write comment?
»
22 months ago, # |
  Vote: I like it 0 Vote: I do not like it

NO. First test case, 100 can be represented with 1 banknote. And so does 1. Basically, you cannot compare it to the final answer.

  • »
    »
    22 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    What do u mean by final answer

    • »
      »
      »
      22 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      For each test case, print one integer — the minimum positive number of burles s that cannot be represented with k or fewer banknotes.

»
22 months ago, # |
Rev. 4   Vote: I like it 0 Vote: I do not like it

You can use binary search in the array a so that you can say that the cost(10^b) = 10^(b-last) where last is the last ai such that ai <= b and use this to solve the problem(this is quite useless since n = 10 but actually optimize it 157598538), otherways I don't where to use binary search. If you meant binary search the answer, it is not possible since the cost(x) does not strictly increment, in a case like a: {0, 4} cost(10000) = 1, cost(9999) = 9999.

»
22 months ago, # |
  Vote: I like it 0 Vote: I do not like it

No. Binary search requires the searchspace to have a special property. If it can be done for some value x then it can be done also for x+1 and it's enough.

(The direction can be reversed, ie x -> x-1).

This problem clearly doesn't satisfy this.

9: 9notes
10: 1 note.
(decreased)
11: 2 notes
(increased)