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 |
我的程序总是WA...能告诉我哪组数据错了么?程序说明: const max=2147483640; maxn=50000; var a:array[1..maxn] of integer; sum:longint; start:word; min,minw,answer,n,c,k,t:longint; f,f2:boolean; Procedure init; var i:longint; begin readln(n); f2:=true;c:=0; for i:=1 to n do read(a[i]); start:=n+1; for i:=1 to n do if a[i]>0 then begin start:=i;break;end; for i:=start+1 to n do if a[i]>0 then begin inc(c);f2:=false;end; if (c=1)or(f2) then start:=n+1; end; Procedure main; var i,t,w:longint; begin answer:=a[start]; min:=0;sum:=a[start];t:=0; for i:=start+1 to n do begin sum:=sum+a[i]; if a[i]>0 then t:=0; if a[i]<0 then t:=t+a[i]; if t<min then begin min:=t;minw:=i;end; if sum-min>answer then answer:=sum-min; if sum<0 then begin sum:=0;min:=0;t:=0;end; end; if (start=n+1)or(f2) then begin answer:=0;min:=-max;t:=-max; for i:=1 to n do if a[i]>=min then begin min:=a[i];w:=i;end; for i:=1 to n do if (a[i]>t)and(i<>w) then t:=a[i]; if start=n+1 then answer:=min+t else answer:=a[start]+min; end; end; Begin Readln(t); for k:=1 to t do begin init; main; writeln(answer); end; End. Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator