- 容易的网络游戏
- 2016-11-11 11:25:42 @
第三个点是不是有点问题?
VAR S:ARRAY[1..1000] OF LONGINT;
X,Y:LONGINT;
N,M,P:LONGINT;
I,K:LONGINT;
SUM:INT64;
PROCEDURE SORT(L,R:LONGINT);
VAR I,J,MID,P:LONGINT;
BEGIN
I:= L;
j:=r;
MID:=S[(I+J)DIV 2];
WHILE I<=J DO
BEGIN
WHILE S[I]>MID DO INC(I);
WHILE S[J]<MID DO DEC(J);
IF I<=J THEN
BEGIN
P:=S[I];
S[I]:=S[J];
S[J]:=P;
INC(I);
DEC(J);
END;
END;
IF I<R THEN SORT(I,R);
IF J>L THEN SORT(L,J);
END;
BEGIN
READLN(N,M,P);
IF P>1000 THEN
IF M>N THEN
K:=N
ELSE K:=M
ELSE IF P+1>M THEN
IF M>N THEN
K:=N
ELSE K:=M
ELSE IF P+1>N THEN
K:=N
ELSE
K:=P+1;
FOR I:=1 TO N DO
BEGIN
READLN(X,Y);
S[I]:=Y-X+1;
END;
SORT(1,N);
SUM:=0;
FOR I:=1 TO K DO
SUM:=SUM+S[I];
WRITELN(SUM);
END.