1 solutions
-
0
C++ :
#include<cstdio> #include<algorithm> using namespace std; unsigned long long ans,n,a[1000039]; int main(){ register int i; scanf("%llu",&n); for(i=1;i<=n;i++) scanf("%llu",&a[i]); sort(a+1,a+n+1); for(i=1;i<=n;i+=2) ans+=a[i]; printf("%llu",ans); }
Pascal :
var a:array[1..1000000] of longint; s,ss:string; i,n:longint; procedure qsort(l,r:longint); var i,j,t,mid:longint; begin i:=l; j:=r; mid:=a[(i+j) div 2]; repeat while a[i]<mid do inc(i); while a[j]>mid do dec(j); if i<=j then begin t:=a[i]; a[i]:=a[j]; a[j]:=t; inc(i); dec(j); end; until i>j; if l<j then qsort(l,j); if i<r then qsort(i,r); end; procedure gjd(s1,s2:string); var a,b,c:array[1..256] of longint; la,lb,lc,t,i:longint; ss,sss:string; begin fillchar(a,sizeof(a),0); fillchar(b,sizeof(b),0); fillchar(c,sizeof(c),0); la:=length(s1); for i:=1 to la do a[la+1-i]:=ord(s1[i])-ord('0'); lb:=length(s2); for i:=1 to lb do b[lb+1-i]:=ord(s2[i])-ord('0'); if la>lb then lc:=la else lc:=lb; t:=0; for i:=1 to lc do begin c[i]:=a[i]+b[i]+t; t:=c[i] div 10; c[i]:=c[i] mod 10; end; if t>0 then begin inc(lc); c[lc]:=t; end; ss:=''; sss:=''; for i:=lc downto 1 do begin str(c[i],ss); sss:=sss+ss; ss:=''; end; s:=sss; end; begin readln(n); for i:=1 to n do readln(a[i]); qsort(1,n); s:='0'; for i:=n downto 1 do begin str(a[i],ss); if i mod 2=1 then gjd(s,ss); end; writeln(s); end.
- 1
Information
- ID
- 606
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By