Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //количество подотрезков отсортированного массива с суммой <= S
- // длина массива = n
- int arr[N];
- int getCount() {
- int left = 0;
- int right = 0;
- int curSum = 0;
- int count = 0;
- while (left < n) {
- while (right < n && curSum + arr[right] <= S) {
- curSum += arr[right];
- right++;
- }
- count += right - left;
- curSum -= arr[left];
- left++;
- }
- return count;
- }
Advertisement
Add Comment
Please, Sign In to add comment