A-BBQ Easy

Source: Internet
Author: User

Score: 200 points

Problem Statement

Snuke is has a barbeque party.

At the party, he'll make N servings of skewer Meal.

Example of a serving of skewer Meal

he has a stock of  2 N  skewers, all of which would be a used in skewer Meal. The length of the  i -th skewer is  L i . Also, he has an infinite supply of ingredients.

to make a serving of skewer Meal, he picks  2  skewers and threads ingredients onto those skewers. Let the length of the shorter skewer be  x , then the serving can hold the maximum of  x  ingredients.

What's the maximum total number of ingredients N a servings of skewer Meal can hold, if he uses the skewers op Timally?

  • 1≦N≦100
  • 1≦Li≦100
  • For each i , was an Li integer.

The input is given from standard input in the following format:

NL1 L2 … L2N

Print The maximum total number of ingredients this Snuke ' s N servings of skewer Meal can hold.

Sample Input 1
21 3 1 2
Sample Output 1

If He makes a serving using the first and third skewers, and another using the second and fourth skewers, each serving wil L hold 1 2 and ingredients 3 .

Sample Input 2
5100 1 2 3 14 15 58 58 58 29
Sample Output 2

Very interesting topic, the order is OK

/************************************************author:guanjuncreated time:2016/7/16 23:23:01File Name: agc1a.cpp*************************************************/#include<iostream>#include<cstring>#include<cstdlib>#include<stdio.h>#include<algorithm>#include<vector>#include<queue>#include<Set>#include<map>#include<string>#include<math.h>#include<stdlib.h>#include<iomanip>#include<list>#include<deque>#include<stack>#defineull unsigned long Long#definell Long Long#defineMoD 90001#defineINF 0x3f3f3f3f#defineMAXN 10010#defineCLE (a) memset (A,0,sizeof (a))Constull inf = 1LL << A;Const Doubleeps=1e-5;using namespaceStd;priority_queue<int,vector<int>,greater<int> >PQ;structnode{intx, y;};structcmp{BOOL operator() (Node A,node b) {if(a.x==b.x)returnA.y>b.y; returnA.x>b.x; }};BOOLcmpintAintb) {    returnA>b;}inta[ -];intMain () {#ifndef Online_judge//freopen ("In.txt", "R", stdin);    #endif    //freopen ("OUT.txt", "w", stdout);    intN;  while(cin>>N) {         for(intI=1; i<=n*2; i++) cin>>A[i]; Sort (a+1, A +1+2*N); intsum=0;  for(intI=2*n;i>=1; i-=2) {sum+=a[i-1]; } cout<<sum<<Endl; }    return 0;}

A-BBQ Easy

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.