You are on page 1of 2

# C Programming

#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

int main()
{
int n,i,j,k,c=0;
scanf("%d",&n);
int *b=malloc(sizeof(int)*n);
for(int a = 0; a < n; a++){
scanf("%d",&b[a]);
}
int d;
int m;
scanf("%d %d",&d,&m);
for(i=0;i<n;i++)
{
k=0;
for(j=i;j<(m+i);j++)
k=k+b[j];
if(k==d)
c++;
}
printf("%d\n",c);
return 0;
}

JAVA Solution
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

## public static void main(String[] args) {

Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] squares = new int[n];
for(int i=0; i < n; i++){
squares[i] = in.nextInt();
}
int count=0;
int d = in.nextInt();
int m = in.nextInt();
for(int i=0;i<n-m+1;i++){
long sum=squares[i];
for(int j=i+1;j<n && j<m+i;j++){
sum+=squares[j];
}
if(sum==d)
count++;
}
System.out.println(count);
}
}