Y2K Accounting Bug (greedy)

Source: Internet
Author: User

Y2K Accounting Bug
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 10945 Accepted: 5499

Description

Accounting for computer machinists (ACM) have sufferred from the Y2K bugs and lost some vital data for preparing annual repo RT for MS Inc.All-what they remember are that Ms Inc. posted a surplus or a deficit each month's 1999 and each month when MS Inc posted Surplus, the amount of surplus is s and each month when MS Inc. posted deficit, the deficit was d. They does 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 the these 8 postings reported a deficit but they does not know how much. The chief accountant is almost sure that MS Inc. was on 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 is possible, what is the maximum amount of surplus that they can post.

Input

Input is a sequence of lines, each containing and positive integers s and d.

Output

For each line of input, output one line containing either a single integer giving the amount of surplus for the entire yea R, or output deficit if it is impossible.

Sample Input

59 237375 743200000) 8496942500000 8000000

Sample Output

11628300612Deficit

Source

Waterloo local 2000.01.29 problem can not understand is flawed, also always thought every month surplus, deficit not the same; Orz (the most owed is here, like also reported a P AH) posts their earnings for each Consecutive 5 months during a year this sentence understanding: every 5 months means 1 ~ 5, 2 ~ 6, 3 ~ 7 ... 8 ~ Orz This also explains that there are 8 sheets for Mao.
1#include <stdio.h>2 intS, D;3 4 intMain ()5 {6    //freopen ("A.txt", "R", stdin);7     intI, earn, II;8      while(~ scanf ("%d%d", &s, &d)) {9          for(i =1; I <5; i++) {Ten             if(I * d > (5-i) *s) One                  Break ; A         } -both =0 ; -         if(i = =4) theboth =1 ; -         if(i = =5) { -Puts ("deficit") ; -             Continue ; +         } -Earn = ( A-2* i-two) * S-(2* i + II) *D; +         if(Earn <0) { Aprintf ("deficit\n") ; at         } -         Else -printf ("%d\n", earn); -     } -     return 0 ; -}
View Code

Y2K Accounting Bug (greedy)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.