Cod sursa(job #2515463)

Utilizator vlad082002Ciocoiu Vlad vlad082002 Data 28 decembrie 2019 17:07:29
Problema Divk Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <iostream>
#include <fstream>
using namespace std;

ifstream fin("divk.in");
ofstream fout("divk.out");

int n, k, a, b, x, s[500010];
long long res;

void citire() {
    fin >> n >> k >>a >> b;
    for(int i = 1; i <= n; i++) {
        fin >> x;
        s[i] = (s[i-1]+x)%k;
    }
}

void solve() {
    for(int i = a; i <= n; i++)
        for(int j = i-b >= 0 ? i-b : 0; i-j >= a; j++)
            if((s[i]-s[j])%k == 0)
                res++;
    fout << res;
}

int main() {
    citire();
    solve();

}