这超时超的,编译器都出不来了,求优化方案

P1478 陶陶摘苹果(升级版)

@[s_TDY](/user/322535) 都10202年了还有人用pascal!
by cstdios @ 2020-02-25 20:40:13


谔谔
by wjh_ @ 2020-02-25 20:42:24


@[s_TDY](/user/322535) 现在这个年头都流行用wenyan
by btng_smith666 @ 2020-02-25 20:44:33


~~__跟不上时代了__~~
by CCCCCreeper @ 2020-02-25 20:47:38


@[s_TDY](/user/322535) ~~现在流行文言、东北话~~
by YUYGFGG @ 2020-02-25 20:50:03


啊艹,熟悉的fpc,让我想起了lazarus和刚入坑OI学pascal的时候 ~~我戏真多~~
by CBW2007 @ 2020-02-25 20:50:40


一只P党来了
by Heap_Sort @ 2020-02-25 21:27:05


@[s_TDY](/user/322535) 您死循环了吧
by Heap_Sort @ 2020-02-25 21:27:31


```pascal for i:=2 to n do if y[i]<y[j] then j:=i; ``` 这句改成 ```pascal for i:=2 to n do if(y[i]<y[j])and(a+b>=x[i]) then j:=i; ```
by Heap_Sort @ 2020-02-25 21:30:27


这是我帮您全部改好后的代码 ```pascal program p1478; var x,y:array[0..5000] of integer; n,s,a,b,i,j,app:integer; begin readln(n,s); readln(a,b); for i:=1 to n do readln(x[i],y[i]); app:=0; y[0]:=32767; while s>=0 do begin j:=0; for i:=1 to n do if(y[i]<y[j])and(a+b>=x[i])then j:=i; if s-y[j]>=0 then begin s:=s-y[j]; app:=app+1; y[j]:=32767; end else break; end; write(app); end. ```
by Heap_Sort @ 2020-02-25 21:43:30


| 下一页