Advertisement
Guest User

bs

a guest
Jan 18th, 2014
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. //true true true true true true true | false false false false
  2. long long MAX_TRUE(bool check(int), long long left, long long right)
  3. {
  4.     long long i = left, j = right, mid;
  5.    
  6.     while (i<j)
  7.     {
  8.         mid  = (i + j)/2;
  9.         if (check (mid))
  10.             i = mid+1;
  11.         else
  12.             j = mid;
  13.     }
  14.     if (check(i))
  15.         return i;  //all true
  16.     else if (i==left)
  17.         return -1; //all false
  18.     else
  19.         return i-1;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement