Problem C:celebrity Split

Source: Internet
Author: User

Topic Description Narration

Problem C:celebrity Split

Jack and Jill had decided to separate and divide their property equally. Each of the their N mansions has a value between 1,000,000 and 40,000,000 dollars. Jack would receive some of the mansions; Jill would receive some of the mansions; The remaining mansions would be sold, and the proceeds split equally.

Neither Jack nor Jill can tolerate the other receiving, with higher total value. The sum of the values of the mansions Jack receives must is equal to the sum of the values of the Mansions Jill receives. So long as the value of the receives are equal, Jack and Jill would like each to receive property of the highest Possibl E value.

Given the values of N mansions, compute the value of the mansions that must being sold so that the rest could divid Ed so as to satisfy Jack and Jill.

Example

Suppose Jack and Jill own 5 mansions valued at 6,000,000, 30,000,000, 3,000,000, 11,000,000, and 3,000,000 dollars. To satisfy their requirements, Jack or Jill would receive the mansion worth 6,000,000 and the other would receive both mans Stions worth 3,000,000 dollars. The Mansions worth 11,000,000 and 30,000,000 dollars would is sold, for a total of 41,000,000 dollars. The answer is therefore 41000000.

Input requirements

The input consists of a sequence of test cases. The first line of all test case contains a single integer N, the number of mansions, which'll be is no more than "This" is followed to N lines, each giving the value of a mansion. The final line of input contains the integer zero. This was not a test case and should wasn't be processed.

Output requirements

For each test case, output a line containing a single integer, the value of the mansions that must is sold so the Res T May is divided so as to satisfy Jack and Jill.

If the input
560000003000000030000001100000030000000
should be output
41000000

#include <iostream> #include <algorithm> #include <vector> #include <string.h> #include < Ctype.h> #include <math.h>using namespace Std;int sum[200],a[200],ans;void fun (); void Divide (int p,int diff, int hav)//p: Number of remaining houses, differ: two-person difference, hav: Two people take the money together {int i,j,n;if (Diff==0&&ans






Problem C:celebrity Split

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.