fork download
  1. #include <iostream>
  2. #include<bits/stdc++.h>
  3. #define fo(i,start,end) for(int i=start;i<end;i++)
  4. using namespace std;
  5.  
  6. int main() {
  7. // your code goes here
  8. int arr[] = {1,0,1,2,3,10};
  9. int n = 6;
  10. int k = 3;
  11. int cnt = 0;
  12. fo(i,0,n){
  13. int sum = 0;
  14. fo(j,i,n){
  15. sum += arr[j];
  16. if(sum == k) cnt++;
  17. }
  18. }
  19. cout<<cnt;
  20.  
  21. return 0;
  22. }
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
3