Computer Machinists (ACM) has sufferred from the Y2K bug and lost
some vital data for preparing annual report for MS Inc.
All what they remember is that MS Inc. posted a surplus or a
deficit each month of 1999 and each month when MS Inc. posted
surplus, the amount of surplus was s and each month when MS Inc.
posted deficit, the deficit was d. They do not remember which or
how many months posted surplus or deficit. MS Inc., unlike other
companies, posts their earnings for each consecutive 5 months
during a year. ACM knows that each of these 8 postings reported a
deficit but they do not know how much. The chief accountant is
almost sure that MS Inc. was about to post surplus for the entire
year of 1999. Almost but not quite.
Write a program, which decides whether MS Inc. suffered a deficit
during 1999, or if a surplus for 1999 was possible, what is the
maximum amount of surplus that they can post.
sequence of lines, each containing two positive integers s and
d.
of input, output one line containing either a single integer giving
the amount of surplus for the entire year, or output Deficit if it
is impossible.
237
743
849694
8000000
MS)
#include
using namespace std;
int main()
{
//freopen("in.txt", "r", stdin);
int
s=0,d=0,money=0,month=0;
while(~scanf("%d%d",&s,&d))
{
money=month=0;
for(int i=1;i<=6;i++)
if(s*i>=d*(5-i))
{
month=i-1;
break;
}//算出来五个月亏钱时最少亏钱月数
//printf("month=%d\n",month);
switch(month)
{
case 0:money=-12*d;break;
case 1:money=3*s-9*d;break;
case 2:money=6*s-6*d;break;
case 3:money=8*s-4*d;break;
case 4:money=10*s-2*d;break;
}
if(money<0)
printf("Deficit\n");
else
printf("%d\n",money);
}
return
0;
}