比赛 |
暑假培训四 |
评测结果 |
AATTTTTTTA |
题目名称 |
采药 |
最终得分 |
30 |
用户昵称 |
Oo湼鞶oO |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-07-21 11:17:30 |
显示代码纯文本
{*******************************************}
{* Program Name:medic *}
{* Input file:medic.in *}
{* Output file:medic.out *}
{* Date:2008.7.21 *}
{* Programmer:Peng Bo *}
{*******************************************}
program medic;
type
jl=record
t,p:word;
b:real;
end;
sz=array[1..100]of jl;
var
s:sz;
m:byte;
t,n:word;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
procedure input;
var
f:text;
i:byte;
begin
assign(f,'medic.in');
reset(f);
readln(f,t,m);
for i:=1 to m do
begin
readln(f,s[i].t,s[i].p);
if s[i].t>t
then
s[i].b:=0
else
s[i].b :=s[i].p/s[i].t;
end;
end;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
procedure px(l,r:byte);
var
i,j:byte;
x:real;
t:jl;
begin
i:=l;
j:=r;
x:=s[(l+r)div 2].b;
repeat
while s[i].b>x do
inc(i);
while x>s[j].b do
dec(j);
if i<=j
then
begin
t:=s[i];
s[i]:=s[j];
s[j]:=t;
inc(i);
dec(j);
end;
until i>j;
if l<j
then
px(l,j);
if i<r
then
px(i,r);
end;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
procedure main(j,k,g:word);
var
i:byte;
begin
for i:=j to m do
if k>=s[i].t
then
main(i+1,k-s[i].t,g+s[i].p)
else
if g>n then n:=g;
end;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
procedure output;
var
f:text;
begin
assign(f,'medic.out');
rewrite(f);
write(f,n);
close(f);
end;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
begin
n:=0;
input;
px(1,m);
main(1,t,0);
output;
end.