fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. int n , k;
  7. cin>>n;
  8. cin>>k;
  9. int arr[n];
  10. for(int i = 0; i<n ; i++){
  11. cin>>arr[i];
  12. }
  13. unordered_map<int,int> mpp;
  14. mpp[0] = 1;
  15. int p[n];
  16. p[0]= arr[0];
  17. for(int i = 0; i< n ; i++){
  18. p[i] = p[i-1] + arr[i];
  19. }
  20. int count = 0;
  21. for(int j = 0; j<n ; j++){
  22. int r = p[j] - k;
  23. count += mpp[r];
  24. mpp[p[j]] += 1;
  25.  
  26. }
  27. cout<<count<<endl;
  28. return 0;
  29. }
Success #stdin #stdout 0.01s 5288KB
stdin
10
8
2 2 3 5 2 2 3 2 2 1
stdout
2