Created
August 20, 2019 13:56
-
-
Save sofhiasouza/f97dcfd495136b5f0ec2b296975f5326 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int bit[N]; | |
int busca_bit(int v) | |
{ | |
int sum = 0; | |
int pos = 0; | |
for(int i = 30 ; i >= 0 ; i--) | |
{ | |
if(pos + (1 << i) < N && sum + bit[pos + (1 << i)] <= v) | |
{ | |
sum += bit[pos + (1 << i)]; | |
pos += (1 << i); | |
} | |
} | |
return pos; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment