fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = (int)100;
  5.  
  6. long long
  7. n, S, a[N + 5], ans;
  8.  
  9. void nhap(){
  10. cin >> n >> S;
  11. for(int i = 1; i <= n; i++) cin >> a[i];
  12. }
  13. void solve(){
  14. for(int L = 1; L <= n; L++){
  15. for(int R = L; R <= n; R++){
  16. long long csum = 0; //lưu tổng đoạn [L; R];
  17. for(int i = L; i <= R; i++){
  18. csum += a[i];
  19. }
  20. if(abs(csum) > S) ans++;
  21. }
  22. }
  23. cout << ans;
  24. }
  25. int main() {
  26. ios_base::sync_with_stdio(0);
  27. cin.tie(0); cout.tie(0);
  28. nhap();
  29. solve();
  30. return 0;
  31. }
Success #stdin #stdout 0.01s 5284KB
stdin
10 7
-4 9 2 -11 -3 8 -6 5 -3 1
stdout
12