比赛 20101117 评测结果 WAWWWAWWWW
题目名称 物品 最终得分 20
用户昵称 nick09 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-17 10:03:07
显示代码纯文本
  1. var i,j,k,n,pi,t,y,x,m,tot,tt:longint;
  2. p1,p2:array[0..1000]of longint;
  3. w:array[0..6000]of longint;
  4. s:string;
  5. r:char;
  6. procedure init;
  7. begin
  8. assign(input,'magica.in');reset(input);
  9. assign(output,'magica.out');rewrite(output);
  10. readln(n,pi);j:=0; tot:=0; tt:=0;
  11. for i:=1 to n do
  12. begin
  13. inc(j);
  14. read(p1[j],r);
  15. inc(tot,p1[j]);
  16.  
  17. if r=' ' then begin read(p2[j]);
  18. if p2[j]-p1[j]-pi>0 then
  19. begin inc(tt,p2[j]-pi);p2[j]:=p2[j]-pi;end;
  20. end
  21.  
  22. end;
  23. end;
  24.  
  25. function maxx(a,b:longint):longint;
  26. begin
  27. if a>b then maxx:=a
  28. else maxx:=b;
  29.  
  30. end;
  31. function max(a,b,c:longint):longint;
  32. begin
  33. if b>a then a:=b;
  34. if c>a then a:=c;
  35. max:=a;
  36.  
  37. end;
  38.  
  39. procedure go;
  40. begin
  41. for i:=1 to n do
  42. for j:=0 to tot do
  43. begin
  44. if j>pi then
  45. w[j]:=max(w[j],w[j]+p1[i],w[j]+p2[i])
  46. else
  47. w[j]:=maxx(w[j],w[j]+p1[i]);
  48. end;
  49.  
  50. end;
  51.  
  52. Begin
  53. init;
  54. n:=j;
  55. go;
  56. writeln(w[tot]);
  57. close(input);close(output);
  58. end.