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 1031. Railway Tickets

Why am i getting wrong answer? here is my scource
Posted by Costel::icerapper@k.ro 27 Feb 2002 18:04
program timus_p1031;
const
  maxn=10000;
  maxk=1000000000;
type
  tart=record
             cost:longint;
             poz:longint;
       end;
  ta=array[1..maxn]of tart;
var
  l1,l2,l3,c1,c2,c3:longint;
  a:ta;
  n:longint;
  x,y:longint;

procedure init_data;
begin
  fillchar(a,sizeof(a),0);
end;

procedure Swap(var x,y:longint);
var
  z:longint;
begin
  z:=x;
  x:=y;
  y:=z;
end;

procedure read_data;
var
  i:longint;
begin
  readln(l1,l2,l3,c1,c2,c3);
  readln(n);
  readln(x,y);
  if x>y then
    Swap(x,y);
  for i:=2 to x-1 do
    readln;
  for i:=x to y do
    readln(a[i].poz);
end;

function TicketCost(st2,st1:longint):longint;
begin
  TicketCost:=0;
  if st2-st1>l3 then
    exit;
  TicketCost:=c3;
  if st2-st1>l2 then
    exit;
  TicketCost:=c2;
  if st2-st1>l1 then
    exit;
  TicketCost:=c1;
end;

procedure TakeChiefestTicket(station:longint);
var
  i:longint;
  d:longint;
begin
  a[station].cost:=maxk+1;
  for i:=station-1 downto x do
  begin
    d:=TicketCost(a[station].poz,a[i].poz);
    if d=0 then
      break;
    if (d+a[i].cost)<a[station].cost then
      a[station].cost:=d+a[i].cost;
  end;
  if a[station].cost>maxk then
    a[station].cost:=maxk+1;
end;

procedure art_solve;
var
  i:longint;
begin
  for i:=x+1 to y do
    TakeChiefestTicket(i);
end;

procedure write_sol;
begin
  writeln(a[y].cost);
end;

begin
  init_data;
  read_data;
  art_solve;
  write_sol;
end.