Pagini recente » Cod sursa (job #1420935) | Cod sursa (job #2730799) | Cod sursa (job #824700) | Cod sursa (job #2105703) | Cod sursa (job #123412)
Cod sursa(job #123412)
#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;
long i, s, j, sum, t, x[4], y[4];
int main() {
freopen("plus.in", "r", stdin);
freopen("plus.out", "w", stdout);
scanf("%ld", &s);
for (i = 1; i <= 3; ++i) {
scanf("%ld%ld", &x[i], &y[i]);
}
for (i = 0; i <= x[1]; ++i) {
sum = s - y[1] * i;
if (y[2] != 0) {
if (y[3] != 0) {
// Calculez intervalul [left, right] in care se plimba
// coeficientul variabilei 3 cand coefiecientul variabilei
// 2 se plimba in [0..x[2]].
long x1 = (sum - 0 * y[2]) * y[3];
long x2 = (sum - x[2] * y[2]) * y[3];
long left = min(x1, x2), right = max(x1, x2);
// Intesectez intervalul [left, right] cu [0, x[3]]
left = max(left, (long) 0);
right = min(right, x[3]);
if (left <= right) {
t += (right - left + 1);
}
} else { // y[3] == 0
long ceva2 = sum * y[2];
if (0 <= ceva2 && ceva2 <= x[2]) {
t += (x[3] + 1);
}
}
} else { // y[2] == 0
//...
}
}
printf("%ld", t);
return 0;
}