求助,打算用递归来做,结果只对了第一个点
查看原帖
求助,打算用递归来做,结果只对了第一个点
36263
阿正楼主2020/10/1 23:54
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int f[10005];
int n;
LL ans=0;
bool cmp(int a,int b){
	return a<b;
} 

int main(){
	//freopen("in.txt","r",stdin);
	scanf("%d",&n);
	
	
	for(int i=1;i<=n;i++)
		scanf("%d",&f[i]);
		
	sort(f+1,f+n+1,cmp);	
	
	//for(int i=1;i<=n;i++)
	//	printf("%d ",f[i]);
		
	for(int i=2;i<=n;i++){
		f[i]=f[i-1]+f[i];
		ans+=f[i];
	}
		
		
	printf("%lld",ans);
	
	return 0;
}
 
2020/10/1 23:54
加载中...