Cod sursa(job #2535594)

Utilizator cyg_Alex_codegicianBarbu Alexandru cyg_Alex_codegician Data 1 februarie 2020 09:03:40
Problema Divk Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.46 kb
#include <fstream>
using namespace std;
ifstream fin ("divk.in");
ofstream fout ("divk.out");
int main()
{
    int n,k,a,b,v[500005],sp[500005],cnt=0;
    fin >> n >> k >> a >> b;
    for (int i=1;i<=n;i++)
    {
        fin >> v[i];
    }
    sp[0]=0;
    for (int i=1;i<=n;i++)
    {
        sp[i]=sp[i-1]+v[i];
    }
    for (int i=a;i<=b;i++)
    {
        for (int j=i;j<=n;j++)
        {
            if ((sp[j]-sp[j-i])%k==0) cnt++;
        }
    }
    fout << cnt;
}