Skip to content

Instantly share code, notes, and snippets.

@musou1500
Created June 9, 2020 16:55
Show Gist options
  • Save musou1500/c65a834ba48ec2bac2c5bffb6b3cd4f3 to your computer and use it in GitHub Desktop.
Save musou1500/c65a834ba48ec2bac2c5bffb6b3cd4f3 to your computer and use it in GitHub Desktop.
using ll = long long;
ll Inchworm(vector<ll> &va, ll k) {
ll left, right, sum, ans;
left = right = sum = ans = 0;
while (left < va.size()) {
while (right < n && sum + va[right] < k) {
sum += va[right];
right++;
}
ll cnt = va.size() - right;
ans += cnt;
sum -= va[left];
if (left == right) {
right++;
sum = 0;
}
left++;
}
return ans;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment