fork download
  1. program diaper;
  2.  
  3. const
  4. MAXN = 100;
  5.  
  6. var
  7. K, N, i, milk, food : LongInt;
  8. F : array[0..MAXN-1] of longint;
  9. B : array[0..MAXN-1] of char; (*per il carattere blank tra il numero e il tipo di pasto*)
  10. T : array[0..MAXN-1] of char;
  11. begin
  12. {
  13.   uncomment the two following lines if you want to read/write from files
  14.   assign(input, 'input.txt'); reset(input);
  15.   assign(output, 'output.txt'); rewrite(output);
  16. }
  17.  
  18. ReadLn(N);
  19.  
  20. for i:=0 to N-1 do readln (F[i],B[i],T[i]);
  21.  
  22. K := 0; milk:=0; food:=0;
  23.  
  24. for i:=0 to N-1 do
  25. begin
  26. if T[i]='M' then
  27. begin
  28. milk:=milk +F[i];
  29. if milk>=50 then begin if i<N-1 then begin K:=K+1; milk:=milk-50;end; end;
  30. end;
  31. if T[i]='B' then
  32. begin
  33. food:=food +F[i];
  34. if food>=80 then begin if i<N-1 then begin K:=K+1; food:=food-80;end; end;
  35. end;
  36. end;
  37.  
  38. WriteLn(K);
  39.  
  40. end.
  41.  
Success #stdin #stdout 0s 5280KB
stdin
6
100 M
80 B
80 B
50 M
1 M
1 M

stdout
5