| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
果然是long long的问题,看来题刷的还不够多啊居然没想到#include <stdio.h>
#include <algorithm>
#include <iostream>
using namespace std;
int main(){
int n,i,j;
long long sum;
while(scanf("%d",&n) != EOF){
long long length[n];
for(i = 0; i < n; i++){
scanf("%I64d",&length[i]);
}
sort(length,length+n);
i = 0;
sum = 0;
while(i < n-1){
length[i+1] = length[i] + length[i+1];
sum += length[i+1];
for(j = i+1; j < n-1; j++){
if(length[j] > length[j+1]){
swap(length[j],length[j+1]);
}
}
i++;
}
printf("%I64d\n",sum);
}
}
数据再大点估计会超时orz
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator