比赛 20130725暑期B班1测 评测结果 AAAAAA
题目名称 黑叔 最终得分 100
用户昵称 李振文 运行时间 0.024 s
代码语言 Pascal 内存使用 3.94 MiB
提交时间 2012-07-18 11:25:13
显示代码纯文本
  1. program a4;
  2. var
  3. a,b:array[1..15000]of longint;
  4. s:array[1..15000]of string;
  5. ss:char;
  6. i,n,j,l,k:longint;
  7. procedure f(i,j:integer);
  8. var
  9. x,y,z,zz:longint;
  10. zzz:string;
  11. begin
  12. x:=i;y:=j;z:=a[(i+j)div 2];
  13. repeat
  14. while a[x]<z do inc(x);
  15. while a[y]>z do dec(y);
  16. if y>=x then begin
  17. zz:=b[x];b[x]:=b[y];b[y]:=zz;
  18. zz:=a[x];a[x]:=a[y];a[y]:=zz;
  19. zzz:=s[x];s[x]:=s[y];s[y]:=zzz;
  20. inc(x);dec(y);end;
  21. until x>y;
  22. if x<j then f(x,j);
  23. if y>i then f(i,y);
  24. end;
  25. procedure ff(i,j:integer);
  26. var
  27. x,y:integer; zzzz:longint;
  28. sss,zzzzz:string;
  29. begin
  30. x:=i;y:=j;zzzzz:=s[(i+j)div 2];
  31. repeat
  32. while s[x]<zzzzz do inc(x);
  33. while s[y]>zzzzz do dec(y);
  34. if y>=x then begin
  35. zzzz:=b[x];b[x]:=b[y];b[y]:=zzzz;
  36. zzzz:=a[x];a[x]:=a[y];a[y]:=zzzz;
  37. sss:=s[x];s[x]:=s[y];s[y]:=sss;
  38. inc(x);dec(y);end;
  39. until x>y;
  40. if x<j then f(x,j);
  41. if y>i then f(i,y);
  42. end;
  43. begin
  44. assign(input,'hey.in');
  45. reset(input);
  46. assign(output,'hey.out');
  47. rewrite(output);
  48. readln(n); ;
  49. for i:=1 to n do begin
  50. read(a[i]);
  51. read(ss);
  52. read(ss);s[i]:=s[i]+ss;
  53. while ss<>' 'do begin
  54. read(ss);if ss<>' 'then s[i]:=s[i]+ss;end;
  55. readln(b[i]);
  56. end;
  57. f(1,n);i:=1;k:=0;
  58. while i<=n do begin
  59. if a[i]<>a[i+1]then begin
  60. if i=1 then begin writeln(s[i],' went out at time ',a[i]);
  61. k:=a[i]+b[i];inc(i);end else begin
  62. if k>=a[i] then begin writeln(s[i],' went out at time ',k);
  63. k:=k+b[i];inc(i);end else begin writeln(s[i],' went out at time ',a[i]);
  64. k:=a[i]+b[i];inc(i);end;end;end else
  65. begin j:=i+1;while a[i]=a[j] do inc(j);ff(i,j-1);
  66. if k<a[i]then k:=a[i];
  67. for l:=i to j-1 do begin
  68. writeln(s[l],' went out at time ',k);k:=k+b[l]end;
  69. i:=j;
  70. end;
  71. end;
  72. close(input);
  73. close(output);
  74. end.