coder__12345's blog

By coder__12345, history, 3 years ago, In English

Problem Link: https://codeforces.me/edu/course/2/lesson/6/2/practice/contest/283932/problem/A

Accepted Code
Not Accepted Code

The only change in the two code is the value being assigned to l, when i normally implement binary search i use it like in the not accepted one but why in this problem its giving wrong answer?

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
3 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by coder__12345 (previous revision, new revision, compare).

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

First code finds point where isfit changes 'sign', if isfit(l) before running BS was = false you don't need to check it anymore, answer is always r. Second code is kind of mix with no clear idea behind it. It should work after changing to while r>l, but 1st is just a lot better concept.

btw mid = (l+r)/2 saves some keystrokes.