Cod sursa(job #1594432)

Utilizator LucianTLucian Trepteanu LucianT Data 9 februarie 2016 14:55:56
Problema Plus Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <cstdio>
#define maxx(a,b) (a>b? a:b)
#define minn(a,b) (a<b? a:b)
using namespace std;
long long a,b,c,x,y,z,s;
long long max1,max2,min1,min2;
long long sol,aux;
int i;
int main()
{
    freopen("plus.in","r",stdin);
    freopen("plus.out","w",stdout);
    scanf("%lld",&s);
    scanf("%lld %lld",&a,&x);
    scanf("%lld %lld",&b,&y);
    scanf("%lld %lld",&c,&z);
    max1=maxx(0,b*y);
    max2=maxx(0,c*z);
    min1=minn(0,b*y);
    min2=minn(0,c*z);
    for(i=0;i<=a;i++,s-=x)
    {
        if(!y)
        {
            if(!z) {if(s==0) sol+=(b+1)*(c+1);}
            else {aux=s/z; if(aux>=0 &&aux<=c) sol+=b+1;}
        }
        else
        {
            if(!z) {aux=s/y; if(aux>=0 && aux<=b) sol+=c+1;}
            else sol+=maxx(0,minn(s-min1,max2)-maxx(s-max1,min2)+1);
        }
    }
    printf("%lld",sol);
    return 0;
}