Skip to content

Instantly share code, notes, and snippets.

@sofhiasouza
Created August 20, 2019 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sofhiasouza/f97dcfd495136b5f0ec2b296975f5326 to your computer and use it in GitHub Desktop.
Save sofhiasouza/f97dcfd495136b5f0ec2b296975f5326 to your computer and use it in GitHub Desktop.
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