- 合并果子
- 2015-07-13 11:09:46 @
{var
ans,i,s,n:longint;
a:array[1..10000]of longint;
procedure sort(l,r:longint);
var
i,j,t,mid:longint;
begin
i:=l;
j:=r;
mid:=a[(i+j)div 2];
while i<=j do
begin
while a[i]<mid do inc(i);
while a[j]>mid do dec(j);
t:=a[i];
a[i]:=a[j];
a[j]:=t;
inc(i);
dec(j);
end;
if i<r then sort(i,r);
if j>l then sort(l,j);
end;
begin
ans:=0;
readln(n);
for i:=1 to n do read(a[i]);
sort(1,n);
s:=a[1];
for i:=2 to n do
begin
s:=s+a[i];
ans:=ans+s;
end;
writeln(ans);
end. }
var
s,i,j,k,p,a,ans:longint;
n:array[1..10000]of longint;
begin
s:=maxlongint;
readln(a);
for i:=1 to a do
begin
read(n[i]);
if n[i]<s then
begin
s:=n[i];
k:=i;
end;
end;
n[k]:=maxlongint;
i:=1;
repeat
inc(i);
p:=maxlongint;
for j:=1 to a do
begin
if p>n[j] then
begin
p:=n[j];
n[j]:=maxlongint;
end;
end;
s:=s+p;
ans:=ans+s;
until i=a;
writeln(ans);
end.
什么情况,求大牛赐教谢谢
3 条评论
-
贱人在我右边 LV 9 @ 2016-12-14 14:55:08
hehehe
-
2016-08-08 15:50:48@
用int64
-
2016-07-27 15:16:31@
longint不够 要用qword
- 1