[HDU] [2803] The MAX

Problem Description

Loading...

Problem Analysis

From the problem statement we can see
we only need to let the largest number be multiplied first
by the largest number it can be multiplied with

Meanwhile, by finding the pattern we can write the code simply

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#include<stdio.h>
#include<algorithm>
using namespace std;
int main() {
	__int64 i,r,N;
	int a[120];
	while(scanf("%I64d",&N),N!=0) {
		for(i=0; i<N; i++) {
			scanf("%d",&a[i]);
		}
		sort(a,a+N);
		r=a[N-1]*(2010-N);
		for(i=1; i<N; i++) {
			r=r+a[N-i-1];
		}
		printf("%I64d\n",r);
	}
	return 0;
}

Problem link: 【HDU】[2803]The MAX

This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...