fork(1) download
  1. var
  2. m,n,i,k,t:integer;
  3. a,b,c:array[1..100,1..2] of integer;
  4. begin
  5. readln(m,n);
  6. for i:=1 to n do begin
  7. readln(a[i,1],b[i,1],c[i,1]);
  8. a[i,2]:=1;
  9. b[i,2]:=0;
  10. c[i,2]:=c[i,1];
  11. end;
  12. k:=0;t:=0;
  13. repeat
  14. t:=t+1;
  15. for i:=1 to n do begin
  16. if c[i,1]=c[i,2] then begin
  17. if a[i,1]=a[i,2] then begin
  18. k:=k+1;
  19. a[i,2]:=1;
  20. inc(b[i,2]);
  21. if b[i,1]=b[i,2] then begin
  22. b[i,2]:=0;
  23. c[i,2]:=0;
  24. end;
  25. end else inc(a[i,2]);
  26. end else inc(c[i,2]);
  27. end;
  28. until k>=m;
  29. writeln(t);
  30. end.
Success #stdin #stdout 0s 232KB
stdin
10 3
1 2 3
3 10 3
2 4 3
stdout
8