0
点赞
收藏
分享

微信扫一扫

uestc The Desire of Asuna 1263 (递推模拟)


The Desire of Asuna


Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)



Submit   Status



ZYHAzwraith用自己心爱的键盘换来了很多支漂亮的荧光棒!

一天,他准备用一条由很多个莹光圈相互连接而成的荧光链送给女神Asuna。每个荧光圈只能由一支荧光棒首尾相接成一个环得到。现在他手中有 n

现在ZYHAzwraith想知道最少需要多少次才能把这些荧光链链拼接成一条长链?



Input

第一行是一个整数 n ( 1≤n≤2000), 表示有 n 条荧光链。 接下来一行有 n 个数,每个数 ai (1≤ai≤105)表示第 i 条链由 ai



Output

输出一个整数表示最少的次数。



Sample input and output

Sample Input

Sample Output

33 2 1

1

34 3 4

2



Hint

第一组样例解释: 



#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
int a[2010];
int main()
{
	int n,i,j,m;
	while(scanf("%d",&n)!=EOF)
	{
		memset(a,0,sizeof(a));
		for(i=0;i<n;i++)
			scanf("%d",&a[i]);
		sort(a,a+n);
		int sum=0,k=n;
		for(i=0;i<n;i++)
		{
			if(sum>=k-1)
				break;
			while(a[i])
			{
				a[i]--;
				sum++;
				if(sum>=k-1)
					break;
			}			
			k--;
		}
		printf("%d\n",sum);
	}
	return 0;
}

举报

相关推荐

0 条评论