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

where is the error?
Posted by cai niao 3 Nov 2001 10:16
I don't think there is any error, but I get a "wrong
answer".

var
    cost: array[1..10000] of longint;
    len: array[1..10000] of longint;
    l1,l2,l3,c1,c2,c3: longint;
    i,j,start,over,n: integer;
begin
    readln(l1,l2,l3,c1,c2,c3);
    readln(n);
    readln(start,over);
    for i:=2 to n do
        readln(len[i]);
    for i:=2 to n do
        cost[i]:=1000000000;
    len[1]:=0;
    cost[start]:=0;
    for i:=start to over-1 do
    begin
        j:=i+1;
        while (len[j]-len[i]<=l3) and (j<=over) do
        begin
            if len[j]-len[i]<=l1 then
            begin
                if cost[i]+c1<cost[j]
                then cost[j]:=cost[i]+c1
            end
            else if len[j]-len[i]<=l2 then
                begin
                    if cost[i]+c2<cost[j]
                    then cost[j]:=cost[i]+c2;
                end
                else if cost[i]+c3<cost[j]
                    then cost[j]:=cost[i]+c3;
            j:=j+1;
        end;
    end;
    writeln(cost[over]);
    read(i);
end.
Re: where is the error?
Posted by Andras Biczo 3 Nov 2001 13:57
I think your error is that the starting stations number can
be greater than the destintations number. In this case you
just have to swap them.