fork download
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. long n = scanner.nextLong();
  7. long k = scanner.nextLong();
  8. long[] b = new long[(int) n];
  9.  
  10. for (int i = 0; i < n; i++) {
  11. b[i] = scanner.nextLong();
  12. }
  13.  
  14. long count = 0;
  15.  
  16. for (int i = 0; i < n; i++) {
  17. long sum = 0;
  18. for (int j = i; j < n; j++) {
  19. sum += b[j];
  20. if (sum <= k) {
  21. count++;
  22. }
  23. }
  24. }
  25.  
  26. System.out.println(count);
  27. scanner.close();
  28. }
  29. }
  30.  
Success #stdin #stdout 0.14s 54572KB
stdin
6 5
1 2 3 4 5 6
stdout
7