Planting Trees(水题)


Planting Trees
Time Limit:1000MS     Memory Limit:131072KB     64bit IO Format:%lld & %llu
Submit   Status   Practice   CSU 1390

Description

Planting Trees(水题)_第1张图片

Input

Output

Sample Input

6
39 38 9 35 39 20 

Sample Output

42 

Hint

Planting Trees(水题)_第2张图片

代码:

#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;

int a[100100];

bool cmp(int a, int b) {
	return a > b;
}
int main()
{
	int n;
	cin >> n;
	for(int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	sort(a, a+n, cmp);
	int max = 0;
	for(int i = 0; i < n; i++) {
		a[i] = a[i] + i + 2;
		if(max < a[i]) max = a[i];
	}
	printf("%d\n", max);
	return 0;
}


你可能感兴趣的:(Planting Trees(水题))