Pagini recente » Cod sursa (job #2726999) | Cod sursa (job #560137) | Cod sursa (job #106999) | Cod sursa (job #1541100) | Cod sursa (job #2547371)
#include <cstdio>
#include <vector>
using namespace std;
vector <int> resturi[100002];
int main() {
freopen("divk.in", "r", stdin);
freopen("divk.out", "w", stdout);
int n, k, a, b, x, sp = 0;
scanf("%d%d%d%d", &n, &k, &a, &b);
for (int i = 0; i < n; i++) {
scanf("%d", &x);
sp = (sp + (x%k))%k;
resturi[sp].push_back(i);
}
int stanga, dreapta;
int solutie = 0;
for (int i = 0; i < k; i++) {
printf("Restul %d: ", i);
if (resturi[i].size() >= 2) {
stanga = 0;
dreapta = 1;
while (dreapta < resturi[i].size() && resturi[i][stanga] <= resturi[i][dreapta]) {
if (resturi[i][dreapta] - resturi[i][stanga] >= a && resturi[i][dreapta] - resturi[i][stanga] <= b)
solutie ++, dreapta ++;
else
if (resturi[i][dreapta] - resturi[i][stanga] < a) {
dreapta ++;
}
else
if (resturi[i][dreapta] - resturi[i][stanga] > b) {
stanga ++;
}
}
}
printf("\n");
}
printf("%d\n", solutie + );
return 0;
}