import java.util.*;
class Ideone {
static int subarray(int arr[], int k) {
int sum = 0;
int count = 0;
int n = arr.length;
int i = 0, j = 0;
while (j < n) {
sum += arr[j];
while (sum > k && i <= j) {
sum -= arr[i];
i++;
}
count += (j - i + 1);
j++;
}
return count;
}
int[] arr = {1, 2, 3, 4};
int k = 5;
System.
out.
println("Count of subarrays: " + subarray
(arr, k
)); }
}
aW1wb3J0IGphdmEudXRpbC4qOwoKY2xhc3MgSWRlb25lIHsKICAgIHN0YXRpYyBpbnQgc3ViYXJyYXkoaW50IGFycltdLCBpbnQgaykgewogICAgICAgIGludCBzdW0gPSAwOwogICAgICAgIGludCBjb3VudCA9IDA7CiAgICAgICAgaW50IG4gPSBhcnIubGVuZ3RoOwogICAgICAgIGludCBpID0gMCwgaiA9IDA7CgogICAgICAgIHdoaWxlIChqIDwgbikgewogICAgICAgICAgICBzdW0gKz0gYXJyW2pdOwoKICAgICAgICAgICAgd2hpbGUgKHN1bSA+IGsgJiYgaSA8PSBqKSB7CiAgICAgICAgICAgICAgICBzdW0gLT0gYXJyW2ldOwogICAgICAgICAgICAgICAgaSsrOwogICAgICAgICAgICB9CgogICAgICAgICAgICBjb3VudCArPSAoaiAtIGkgKyAxKTsKICAgICAgICAgICAgaisrOwogICAgICAgIH0KCiAgICAgICAgcmV0dXJuIGNvdW50OwogICAgfQoKICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIHRocm93cyBqYXZhLmxhbmcuRXhjZXB0aW9uIHsKICAgICAgICBpbnRbXSBhcnIgPSB7MSwgMiwgMywgNH07CiAgICAgICAgaW50IGsgPSA1OyAKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIkNvdW50IG9mIHN1YmFycmF5czogIiArIHN1YmFycmF5KGFyciwgaykpOwogICAgfQp9Cg==