Cod sursa(job #2175222)

Utilizator arcoC. Nicolae arco Data 16 martie 2018 16:03:14
Problema Divk Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.22 kb
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    ifstream in("divk.in");
    ofstream out("divk.out");
    if(in.is_open() && out.is_open())
    {
        int n, k, a, b;
        in >> n >> k >> a >> b;
        int *sume = new int[n];

        for(int i = 0; i < n; i++)
        {
            int t;
            in >> t;
            //cout << t << "\n";
            if(i)
            {
                sume[i] = sume[i - 1] + t;
            }
            else
            {
                sume[0] = t;
            }
        }
        int count  = 0;
        for(int i = a - 1; i < b; i++)
        {
            for(int j = 0; (j + i) < n; j++)
            {
                int rez;
                if(j)
                {
                    rez = sume[j + i] - sume[j - 1];
                }
                else
                {
                    rez = sume[j + i];
                }
                //cout << j << " " << j + i << " " << rez << "\n";
                if(rez % k == 0)
                {
                    count++;
                }
            }
        }
        out << count;
        in.close();
        out.close();
    }

    return 0;
}