HDU 1171 big event in HDU

Source: Internet
Author: User

Big event in HDU Time Limit: 10000/5000 MS (Java/others) memory limit: 65536/32768 K (Java/Others) Total submission (s): 22611 accepted submission (s): 7942

Problem description Nowadays, we all know that computer College is the biggest department in HDU. But, maybe you don't know that computer College had ever been split into computer College and software College in 2002.
The splitting is absolutely a big event in HDU! At the same time, it is a trouble thing too. all facilities must go halves. first, all facilities are assessed, and two facilities are thought to be same if they have the same value. it is assumed that there is n (0 <n <1000) kinds of facilities (different value, different kinds ).
 
Input Input contains multiple test cases. each test case starts with a number N (0 <n <= 50 -- the total number of different facilities ). the next n lines contain an integer v (0 <v <= 50 -- Value of facility) and an integer m (0 <m <= 100 -- corresponding number of the facilities) each. you can assume that all V are different.
A test case starting with a negative integer terminates input and this test case is not to be processed.
 
Output For each case, print one line containing two integers A and B which denote the value of computer College and software college will get respectively. A and B shoshould be as equal as possible. at the same time, You shoshould guarantee that A is not less than B.
 
Sample Input
 
210 120 1310 1 20 230 1-1
 
Sample output
 
20 1040 40
  Question: Give the value of each object and the number of objects, and how to make the value obtained by a and B the closest and the value of a cannot be less than B

<Span style = "font-size: 18px;" >#include <stdio. h ># include <iostream> using namespace STD; int DP [500000]; int V [10000]; int max (int x, int y) {return (x> Y? X: Y) ;}int main () {int t, a, B, I, j; int sum, L; while (CIN> T) {If (T <0) break; sum = 0; L = 0; memset (DP, 0, sizeof (DP); memset (v, 0, sizeof (v); for (I = 1; I <= T; I ++) {CIN> A> B; while (B --) // Replace the I-th item with the item {v [L ++] = A; sum + = A ;}} for (I = 0; I <L; I ++) // 01 backpack (L items) for (j = sum/2; j> = V [I]; j --) // "backpack capacity" is half of the total value DP [J] = max (DP [J], DP [J-V [I] + V [I]); cout <sum-DP [sum/2] <<'' <DP [sum/2] <Endl ;}return 0 ;}</span>


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.