Cod sursa(job #117234)

Utilizator DastasIonescu Vlad Dastas Data 20 decembrie 2007 23:18:46
Problema Plus Scor 25
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.98 kb
#include <cstdio>

FILE *in = fopen("plus.in","r"), *out = fopen("plus.out","w");

int s;
int a, b,
    c, d,
    e, f;

long long sol;

int main()
{
    fscanf(in, "%d %d %d %d %d %d %d", &s, &a,&b,&c,&d,&e,&f);
    //printf("%d %d\n%d %d\n%d %d\n", a, b, c, d, e, f);

    for ( int i = 0; i <= a; ++i )
        for ( int j = 0; j <= c; ++j )
        {
            int t = i*b + j*d;

            if ( f == -1 )
            {
                if ( e*f + t <= s && t > s )
                    ++sol;
            }
            else if ( f == 0 )
            {
                if ( e*f == s )
                    sol = sol + e + 1;
            }
            else
            {
                if ( e*f + t >= s )
                    ++sol;
            }
        }

    fprintf(out, "%lld\n", sol == 0 ? sol + 1 : sol);

	return 0;
}

/*
           for ( int k = 0; k <= e; ++k )
                if ( i*b + j*d + k*f == s )
                    ++sol;
*/