ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1200. Horns and Hoofs

I can't understand, what's wrong with my program. Help, please
Posted by Mephistos 19 Mar 2002 17:24
type
  Sum = record
    Rub, Kop:LongInt;
  end;

var
  A, B:Sum;
  K:LongInt;

procedure Inp;
var
  _A, _B:Extended;
begin
  Read(_A, _B);
  A.Rub:=Round(_A*100) div 100;
  A.Kop:=Round(_A*100) mod 100;
  B.Rub:=Round(_B*100) div 100;
  B.Kop:=Round(_B*100) mod 100;
  Read(K);
end;

procedure Profit(Coeff:Sum; Count:LongInt; var P:Sum);
begin
  P.Rub:=Count*(Coeff.Rub-Count)+(Count*Coeff.Kop) div 100;
  P.Kop:=(Count*Coeff.Kop) mod 100;
end;

function FindMax(V:Sum):LongInt;
var
  P, Bp:sum;
  I, Max:LongInt;
begin
  FillChar(Bp, Sizeof(Bp), 0);

  for I:=0 to K do
    begin
      Profit(V, I, P);
      if (P.Rub>Bp.Rub) or ((P.Rub=Bp.Rub) and (P.Kop>Bp.Kop)) then
        begin
          Max:=I;
          BP:=P;
        end;
    end;

  FindMax:=Max;
end;

var
 BX, BY:LongInt;
 BP:Sum;

procedure Run;
var
  Xmax, Ymax:LongInt;
  X, Y:LongInt;
  P, Py:Sum;
  I, J:LongInt;
begin
  FillChar(Bp, Sizeof(BP), 0);
  Xmax:=FindMax(A);
  Ymax:=FindMax(B);
  for I:=0 to K do
    begin
      X:=I;
      if (X>XMax) then X:=XMax;
      Y:=K-I;
      if (Y>YMax) then Y:=YMax;

      P.Rub:=0; P.Kop:=0;
      Profit(A, X, P);
      Profit(B, Y, Py);
      P.Rub:=P.Rub+Py.Rub+(P.Kop+Py.Kop) div 100;
      P.Kop:=(P.Kop+Py.Kop) mod 100;
      if (P.Rub>BP.Rub) or ((P.Rub=Bp.Rub) and (P.Kop>Bp.Kop)) then
        begin
          BP:=P;
          BX:=X;
          BY:=Y;
        end;
    end;
end;

procedure Out;
begin
  Write(Bp.Rub, '.');
  if (BP.Kop<10) then Write(0, BP.Kop mod 100)
  else if (BP.Kop mod 100=0) then Write('00')
  else Write(BP.Kop mod 100);
  WriteLn;

  WriteLn(Bx, ' ', BY);
end;

begin
{  Assign(Input, 'Input.txt');
  Reset(Input);}

  Inp;
  Run;
  Out;

{  Close(Input);}
end.