BZOJ1334: [Baltic2008]elect

Source: Internet
Author: User

1334: [Baltic2008]elect time limit:10 Sec Memory limit:162 MB
Submit:386 solved:201
[Submit] [Status] Descriptionn political parties to form a joint cabinet, Each party has its own number of seats. Now I want you to find a way to select a party that has more than half the number of seats, and the number of seats in the Union cabinet is better. For a coalition cabinet, if a party exits, the other party is still more than half the total number of seats, this party is called superfluous, this is not allowed. The first line of input gives How many political parties are there? The value is less than or equal to 300 the number of seats per party is given below. Total number of seats less than or equal to 100000Output the maximum number of seats in your cabinet plan. Sample Input4
1 3 2 4
Sample Output7Exercises
We can think of it as legitimate if the smallest of the elected seats is less than half the number that is removed.
Then we'll make a backpack from big to small. Update ans by the way
Code:
1#include <cstdio>2 3#include <cstdlib>4 5#include <cmath>6 7#include <cstring>8 9#include <algorithm>Ten  One#include <iostream> A  -#include <vector> -  the#include <map> -  -#include <Set> -  +#include <queue> -  +#include <string> A  at #defineINF 1000000000 -  - #defineMAXN 100000+5 -  - #defineMAXM 20000000+5 -  in #defineEPS 1e-10 -  to #definell Long Long +  - #definePA pair<int,int> the  * #defineFor0 (i,n) for (int i=0;i<= (n); i++) $ Panax Notoginseng #defineFor1 (i,n) for (int i=1;i<= (n); i++) -  the #defineFor2 (i,x,y) for (int i= (x); i<= (y); i++) +  A #defineFor3 (i,x,y) for (int i= (x); i>= (y); i--) the  + #defineMoD 1000000007 -  $ using namespacestd; $  -InlineintRead () -  the { - Wuyi     intx=0, f=1;CharCh=GetChar (); the  -      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} Wu  -      while(ch>='0'&&ch<='9') {x=Ten*x+ch-'0'; ch=GetChar ();} About  $     returnx*F; -  - } - intN,M,A[MAXN]; A BOOLF[MAXN]; +  the intMain () -  $ { the  theFreopen ("Input.txt","R", stdin); the  theFreopen ("output.txt","W", stdout); -  inn=read (); theFor1 (I,n) A[i]=read (), m+=A[i]; theSort (A +1, a+n+1); Aboutf[0]=1;intans=0; theFor3 (I,n,1) theFor3 (J,m-a[i],0) the       if(F[j]) +       { -f[j+a[i]]=1; the           if(j<=m/2&&j+a[i]>m/2) Ans=max (ans,j+a[i]);Bayi       } theprintf"%d\n", ans); the  -     return 0; -  the}
View Code

BZOJ1334: [Baltic2008]elect

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.