We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent cea2689 commit 368880aCopy full SHA for 368880a
library/data_structures/bit_uncommon/walk.hpp
@@ -1,10 +1,10 @@
1
//! Requires s[i] >= 0
2
-//! max pos such that sum of [0,pos) < sum, or -1
+//! max r such that sum of [0,r) < sum, or -1
3
int walk(ll sum) {
4
if (sum <= 0) return -1;
5
- int pos = 0;
+ int r = 0;
6
for (int pw = bit_floor(size(s)); pw; pw >>= 1)
7
- if (pos + pw <= sz(s) && s[pos + pw - 1] < sum)
8
- pos += pw, sum -= s[pos - 1];
9
- return pos;
+ if (r + pw <= sz(s) && s[r + pw - 1] < sum)
+ sum -= s[(r += pw) - 1];
+ return r;
10
}
0 commit comments