比赛 暑假培训B班二测 评测结果 AWWWWWWWWWW
题目名称 待售干草 最终得分 9
用户昵称 英雄寞乌云然 运行时间 0.004 s
代码语言 Pascal 内存使用 0.54 MiB
提交时间 2012-07-22 10:31:14
显示代码纯文本
  1. program fl;
  2. var
  3. s:array[1..100000] of longint;
  4. a,b,c,d,m,n,i,j,k,h,zl:longint;
  5. procedure kuaipai(l,r:longint);
  6. var i,j,x,y:longint;
  7. begin
  8. i:=l; j:=r; x:=s[(l+r) div 2];
  9. repeat
  10. while s[i]<x do inc(i);
  11. while x<s[j] do dec(j);
  12. if i<=j then
  13. begin
  14. y:=s[i]; s[i]:=s[j]; s[j]:=y;inc(i);dec(j);
  15. end;
  16. until i>j;
  17. if l<j then kuaipai(l,j);
  18. if i<r then kuaipai(i,r);
  19. end;
  20. begin
  21. assign(input,'hay4sale.in');
  22. reset(input);
  23. assign(output,'hay4sale.out');
  24. rewrite(output);
  25. read(n,m);
  26. for a:=1 to m do
  27. begin read(i); s[a]:=i; end;
  28. kuaipai(1,m);
  29. h:=1;
  30. repeat
  31. begin
  32. zl:=s[h]+zl;
  33. h:=h+1;
  34. end;
  35. until zl>=n ;
  36. if zl>n then zl:=zl-s[h-1];
  37. write(zl);
  38.  
  39.  
  40. close(input);
  41. close(output);
  42. end.
  43.  
  44.  
  45.  
  46.  
  47.