fork download
  1. #include <iostream>
  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. int count = 0;
  14. for(int i = 0; i<n; i++){
  15. int sum = 0;
  16. for(int j = i; j<n;j++){
  17. sum += arr[j];
  18. if(sum == k){
  19. count++;
  20. }
  21. }
  22. }
  23. cout<<count<<endl;
  24. return 0;
  25. }
Success #stdin #stdout 0s 5320KB
stdin
10
8
2 2 3 5 2 2 3 2 2 1
stdout
2