Advertisement
Guest User

:)

a guest
Feb 25th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. type mat=array[0..2001,0..2002] of longint;
  2.  
  3. var a:mat;
  4.  
  5. i,j,k,n,st,dr,dif,col,p:longint;
  6. f,g:text;
  7.  
  8.  
  9. begin
  10. assign(f,'summax1.in');
  11. assign(g,'summax1.out');
  12. reset(f);
  13. rewrite(g);
  14. read(f,p);
  15. read(f,n,st,dr);
  16. for i:=1 to n do begin
  17. for j:=1 to i do
  18. read(f,a[i,j]);
  19. end;
  20.  
  21. for j:=1 to n do
  22. a[j-1,n]:=1;
  23.  
  24. for i:=n-1 downto 1 do
  25. for j:=1 to i do
  26. if a[i+1,j]>a[i+1,j+1] then
  27. begin
  28. a[i,j]:=a[i,j]+a[i+1,j];
  29. a[j-1,i]:=a[j-1,i+1];
  30. end
  31. else
  32. begin
  33. a[i,j]:=a[i,j]+a[i+1,j+1];
  34. a[j-1,i]:=a[j,i+1];
  35. if a[i+1,j]=a[i+1,j+1] then
  36. if a[j-1,i]>2000000000-a[j-1,i+1] then
  37. a[j-1,i]:=2000000001
  38. else
  39. a[j-1,i]:=a[j-1,i]+a[j-1,i+1];
  40. end;
  41. if p=1 then
  42. writeln(g,a[0,1]) {a[0,1]}
  43. else
  44. begin
  45. for k:=st to dr do
  46. begin
  47. write(g,1);
  48. dif:=k;
  49. col:=1;
  50. for i:=2 to n do
  51. if (a[col-1,i]>=dif) and (a[i,col]>=a[i,col+1]) then
  52. begin
  53. write(g,' ',col);
  54. end
  55. else
  56. begin
  57. if a[i,col]=a[i,col+1] then
  58. dif:=dif-a[col-1,i];
  59. col:=col+1;
  60. write(g,' ',col);
  61.  
  62. end;
  63. writeln(g);
  64. end;
  65. end;
  66. close(f);
  67. close(g);
  68. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement