fork download
  1. /*
  2. * @Author: hungeazy
  3. * @Date: 2026-03-04 23:24:15
  4. * @Last Modified by: hungeazy
  5. * @Last Modified time: 2026-03-13 20:13:12
  6. */
  7. #include <bits/stdc++.h>
  8. using namespace std;
  9. #define int long long
  10. const int N = 100010;
  11. int n,k,a[N],pre[N];
  12.  
  13. signed main()
  14. {
  15. ios_base::sync_with_stdio(false);
  16. cin.tie(NULL); cout.tie(NULL);
  17. cin >> n >> k;
  18. for (int i = 1; i <= n; i++)
  19. {
  20. cin >> a[i];
  21. pre[i] = pre[i-1]+a[i];
  22. }
  23. int ans = 0;
  24. for (int i = 1; i <= n; i++)
  25. {
  26. int l = i, r = n, pos = 0;
  27. while (l <= r)
  28. {
  29. int mid = (l+r)>>1;
  30. if (pre[mid]-pre[i-1] < k) l = mid+1;
  31. else
  32. {
  33. pos = mid;
  34. r = mid-1;
  35. }
  36. }
  37. if (pos != 0) ans += n-pos+1;
  38. }
  39. cout << ans;
  40. return 0;
  41. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty