n number, divided into two groups, so that the sum of two sets of the maximum value of the smallest

Source: Internet
Author: User

Title Description: There are two from the processor, each processor processing speed is the same, give you a set of data, how to allocate so that the fastest processing of this set of data, output the fastest processing time.

Input: 6

5, 9,3,6,8,7

Output: 20

Input: 3

The

Output: 3

#include <stdio.h>
int main ()
{
	int i,j,s1,s2,n,a[100];
	scanf ("%d", &n);
	for (i=0;i<n;i++)
	{
		scanf ("%d", &a[i]);
	} 
	Sorts this array from large to small for 
	(i=0;i<n;i++)
	{for
		(j=0;j<n-i-1;j++)
		{
			if (a[j]<a[j+1])
			{
				int t=a[j];
				A[J]=A[J+1];
				A[j+1]=t
	;
	}}} s1=s2=0;
	
	for (i=0;i<n;i++)
	{
		//The first to add the next data after execution (is ordered, so the maximum number is added) 
		if (s1<s2)
		{
			s1+=a[i];
		} else{
			s2+=a[i];
		}
	}
	Output maximum number of 
	printf ("%d\n", (S1>S2)? s1:s2);
}



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.