Cod sursa(job #613659)

Utilizator Magnuscont cu nume gresit sau fals Magnus Data 3 octombrie 2011 10:46:55
Problema Plus Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.03 kb
#include <cmath>
#include <cstdio>

using namespace std;

long long i,n,j,s,sol,x[4],y[4],s2,l,r,x3,x4,x1,x2;
inline long long min(long long aux1,long long aux2){if (aux1<aux2) return aux1;else return aux2;}
inline long long max(long long aux1,long long aux2){if (aux1>aux2) return aux1;else return aux2;}

int main()
{
	freopen("plus.in","r",stdin);
	freopen("plus.out","w",stdout);
	scanf("%lld",&n);
	for(i=1;i<=3;++i)
		scanf("%lld%lld",&x[i],&y[i]);
	for(i=0;i<=x[1];++i)
    {
		s=n-y[1]*i;
		if (y[2]!=0)
		{
			if (y[3]!=0)
			{
				x1=(s-0*y[2])*y[3];
				x2=(s-x[2]*y[2])*y[3];
				l=min(x1,x2);
				r=max(x1, x2);
				l=max(l,(long long)0);
				r = min(r,x[3]);
				if (l<=r)
					sol+=(r-l+1);
			}
			else
			{
				x3=s*y[2];
				if (0<=x3&&x3<=x[2])
					sol+=(x[3]+1);
			}
		}
		else
		{
            if (y[3]==0)
			{
				if (s==0)
					sol+=(x[2]+1)*(x[3]+1);
			}
			else
			{
				x4=s/y[3];
				if (x4>=0&&x4<=x[3])
					sol+=x[2]+1;
			}
		}
 	}
	printf("%lld",sol);
	return 0;
}