1 条题解
-
0hz4zlujunyang LV 8 MOD @ 2017-10-27 14:51:04
发布Pascal题解:
var n,i,j:longint; ma,su:int64; a:array[0..100001,1..2] of longint; procedure kp(l,r:longint); var mid,i,p,j:longint; begin i:=l; j:=r; mid:=a[(i+j) div 2,1]; repeat while a[i,1]<mid do inc(i); while a[j,1]>mid do dec(j); if j>=i then begin p:=a[i,1]; a[i,1]:=a[j,1]; a[j,1]:=p; p:=a[i,2]; a[i,2]:=a[j,2]; a[j,2]:=p; inc(i); dec(j); end; until i>j; if i<r then kp(i,r); if l<j then kp(l,j); end; begin su:=0; fillchar(a,sizeof(a),0); a[0,2]:=-1; readln(n); a[n+1,2]:=-1; for i:=1 to n do readln(a[i,2],a[i,1]); kp(1,n); i:=1; j:=n; while i<=j do begin while a[i,2]=0 do inc(i); while a[j,2]=0 do dec(j); ma:=a[i,1]+a[j,1]; if ma>su then su:=ma; if a[i,2]>a[j,2] then begin a[i,2]:=a[i,2]-a[j,2]; dec(j); end else begin a[j,2]:=a[j,2]-a[i,2]; inc(i); end; end; writeln(su); end.
- 1
信息
- 难度
- 9
- 分类
- (无)
- 标签
- (无)
- 递交数
- 4
- 已通过
- 1
- 通过率
- 25%
- 上传者