Pagini recente » Cod sursa (job #2265674) | Cod sursa (job #1832782) | Cod sursa (job #1634700) | Cod sursa (job #2162727) | Cod sursa (job #485476)
Cod sursa(job #485476)
#include <cstdio>
#include <algorithm>
using namespace std;
int S;
int NrBile[3], Numar[3];
int Left[3], Right[3];
inline int between(int x, int lft, int rgt) {
return lft <= x && x <= rgt;
}
int main() {
freopen("plus.in", "rt", stdin);
freopen("plus.out", "wt", stdout);
scanf("%d", &S);
for (int i = 0; i < 3; ++i) {
scanf("%d %d", NrBile + i, Numar + i);
if (Numar[i] == -1) {
Left[i] = -NrBile[i];
Right[i] = 0;
} else {
Left[i] = 0;
Right[i] = NrBile[i];
}
}
long long num_sol = 0;
int tempS, x, y, cnt;
for (int i = 0; i <= NrBile[0]; ++i) {
tempS = S - i * Numar[0];
if (Numar[1] == 0) {
if (Numar[2] == 0) {
num_sol += (tempS == 0) * (long long) (NrBile[1] + 1) * (NrBile[2] + 1);
} else {
num_sol += between(tempS, Left[2], Right[2]) * (NrBile[1] + 1);
}
} else {
if (Numar[2] == 0) {
num_sol += between(tempS, Left[1], Right[1]) * (NrBile[2] + 1);
} else {
x = tempS - Right[1];
y = tempS - Left[1];
/*
printf("tempS = %d, x = %d, y = %d, Left[2] = %d, Right[2] = %d\n",
tempS, x, y, Left[2], Right[2]);
*/
cnt = min(y, Right[2]) - max(x, Left[2]) + 1;
cnt = max(cnt, 0);
num_sol += cnt;
}
}
}
printf("%lld\n", num_sol);
return 0;
}