Wii game started to pull (Baidu 07 competition question 2)

Source: Internet
Author: User

In order to make it easier for employees during intense work hours, massage chairs, CD, golf sets, and Wii game consoles are placed in the Baidu Lounge.

Leisure products. Of course, the most popular among them are game consoles.

Two batteries are required for each handle of the Wii Game Machine (these two batteries can be of different brands ).

Engineers are playing games.

If the handle

If there is no electricity, they will take the unpowered battery away and replace it with a brand new battery. If there is electricity, they must continue to use it.

For example, three batteries are available for 3 hours, 5 hours, and 8 hours. Initially, engineers used 3 and 5 hours

Battery. 3 hours later, change to an 8-hour period. After 2 hours, the battery will no longer be available when the handle is no longer powered.

However, if

The eight-hour battery can be used for 8 hours at the beginning.

Calculate the minimum and maximum number of batteries for each brand and the number of batteries of the brand.

Input Format

Enter the first positive integer N, indicating the number of batteries. In the next n rows, each line contains two integers, L and F, indicating that the time is L.

There are f batteries.

Output Format

Only one line of output contains two integers, indicating the engineer's shortest game time and longest game time (short time before ). Two

Integers are separated by spaces.

Input example

3

3 2

5 2

8 2

Output example

5 8

The following is the source code. The above output sample is provided by Baidu, but it should be wrong. The maximum value is obviously 16, the minimum value calculated by the program is 13 # include <iostream> # include <vector> # include <fstream> using namespace STD; static int minmum = 10000; static int maxmum = 0; typedef struct {int time; int num;} battery; void inputall (ifstream & in, vector <battery> & V) {int types; battery BAT; char Buf [100]; in> types; For (INT I = 0; I <types; I ++) {In> bat. time> bat. num; V. push_back (BAT) ;}} bool checkexist (battery BAT) {If (BAT. num> = 1) return true; return false;} bool checkside (INT ltype, int Rtype) {If (ltype> = Rtype) return true; return false ;} void process (vector <battery> V, int ltype, int Rtype, int sum) {int flag = 0; If (checkside (ltype, Rtype) {sum + = Rtype; for (INT I = 0; I <v. size (); I ++) {If (checkexist (V [I]) {flag ++; (V [I]. num) --; process (v, (ltype-Rtype), V [I]. time, sum); (V [I]. num) ++ ;}}if (flag = 0) {If (sum> maxmum) maxmum = sum; If (sum <minmum) minmum = sum; return ;}} else {sum + = ltype; For (INT I = 0; I <v. size (); I ++) {If (checkexist (V [I]) {flag ++; (V [I]. num) --; process (V, V [I]. time, (Rtype-ltype), sum); (V [I]. num) ++ ;}}if (flag = 0) {If (sum> maxmum) maxmum = sum; If (sum <minmum) minmum = sum; return ;}} return;} int main () {vector <battery> V; ifstream in ("input.txt"); inputall (in, V); process (v, 0, 0, 0 ); cout <minmum <"" <maxmum <Endl ;}

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.