fork download
  1. #include <vector>
  2. using namespace std;
  3.  
  4. // Function to count subarrays having sum less than k
  5. int countsubarray(vector<int> &arr, int k)
  6. {
  7. int n = arr.size();
  8. int start = 0;
  9. int sum = 0;
  10. int count = 0;
  11.  
  12. // Move end pointer
  13. for (int end = 0; end < n; end++)
  14. {
  15. sum += arr[end];
  16.  
  17. // If sum becomes too large, shrink the window
  18. while (sum >= k)
  19. {
  20. sum -= arr[start];
  21. start++;
  22. }
  23.  
  24. // Count valid subarrays ending at end
  25. count += (end - start + 1);
  26. }
  27.  
  28. return count;
  29. }
  30.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty