poj 3253(水题)
作者:互联网
#include<iostream> #include<algorithm> using namespace std; int cmp(long long p,long long q){ if(p>q)return true; return false; } int main(){ int n,i,j; long long data[20005],result,tmp; scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d",&data[i]); } result = 0; sort(data,data+n,cmp); for(i=0;i<n-1;i++){ data[n-2-i] = data[n-2-i]+data[n-1-i]; result += data[n-2-i]; tmp = data[n-2-i]; for(j=n-2-i;j>=1;j--){ if(data[j-1]<tmp){ data[j] = data[j-1]; } else{ break; } } data[j] = tmp; } if(n==1) printf("%lld\n",data[0]); else printf("%lld\n",result); return 0; }
标签:std,return,水题,int,3253,long,poj,include,data 来源: https://www.cnblogs.com/stevenzrx/p/15640067.html