Statistics

Problem Statement for "TrainDispatch"

Problem Statement

PROBLEM STATEMENT
You own four passenger wagons that weigh 30t each, six mail wagons that weigh
20t each, a train engine capable of hauling 100t, and a rail connection between
Baltimore and Washington D.C.  Each day your train goes from Washington D.C. to
Baltimore and returns from Baltimore to Washington D.C.  Each day there may be
passengers or mail bags waiting at the Baltimore station to be taken to
Washington D.C. and there may be passengers or mail bags waiting at the
Washington D.C. station to be taken to Baltimore.  On the first day all of your
wagons and your train engine are in Washington, but at each station stop you
can detach wagons and leave them there or attach any wagons that might be
available.

Given a schedule of full passenger wagon amounts and full mail bag wagon
amounts at both stations during a period of 3 days, write a method that
determines the maximum amount of profit that your train can fetch.  Assume that
it costs $1000 to take the train from one station to another regardless of how
many wagons are attached, that each wagon full of passengers yields a revenue
of $3000, while each wagon full of mailbags yields a revenue of $2000, and that
your train must go from Washington to Baltimore and then back on each of the
three days even if no profit or a loss occurs.  If no profit can be made or a
loss occurs then the method should return 0.

DEFINITION
Class Name: TrainDispatch
Method Name: maximumProfit
Parameters: String[]
Return:     int
Method Signature:  (be sure your method is public) int maximumProfit(String[]
schedule)

NOTES
- Each element of the input String[] represents a separate day and is in the
follwoing format:  "A,B;C,D".
- A is the number of wagons that can be filled with passengers in Washington
D.C. that day.
- B is the number of wagons that can be filled with mail in Washington D.C.
that day.
- C is the number of wagons that can be filled with passengers in Baltimore
that day.
- D is the number of wagons that can be filled with mail in Baltimore that
day.  
  - A,B,C,D are all integers between 0 and 100 inclusive.
- Assume that a wagon weighs the same whether full or empty.
- Keep in mind that you have a fixed number of wagons of each type available.
- You may choose to detatch wagons at stations at no extra cost.

TopCoder will ensure that: 
- The String[] will have 3 elements.
- Each each element of the String[] is in the proper format as described in the
NOTES section.

EXAMPLES
maximumProfit({"5,2;2,4","4,1;3,1","1,8;9,8"})  returns 52000
1st Day:  W-->B  take 2 full passenger wagons and 2 full mail wagons  profit:9000
          B-->W  take 2 full passenger wagons and 2 full mail wagons         9000
2nd Day:  W-->B  take 3 full passenger wagons and 0 full mail wagons         8000
          B-->W  take 3 full passenger wagons and 0 full mail wagons         8000
3rd Day:  W-->B  take 0 full passenger wagons and 5 full mail wagons         9000
          B-->W  take 0 full passenger wagons and 5 full mail wagons         9000

-------
                                                                            52000
maximumProfit({"2,0;2,0","2,0;2,0","2,0;0,5"})  returns 34000
1st Day:  W-->B  take 2 full passenger wagons and 2 empty mail wagons
profit:5000
B-->W  take 2 full passenger wagons and 0 mail wagons
5000
                 (and there are now 2 empty mail wagons available in Washington)
2nd Day:  W-->B  take 2 full passenger wagons and 2 empty mail wagons
5000
B-->W  take 2 full passenger wagons and 0 mail wagons
5000
                 (and there are now 4 empty mail wagons available in Washington)
3rd Day:  W-->B  take 2 full passenger wagons and 1 empty mail wagon
5000
B-->W  take 0 passenger wagons      and 5 full mail wagons
9000

-------

34000

maximumProfit({"0,0;0,0","0,0;0,0","0,0;0,0"})  returns 0
maximumProfit({"2,2;2,3","2,4;2,6","2,3;0,5"})  returns 50000
maximumProfit({"8,9;12,14","2,4;5,5","3,5;3,2"})  returns 54000

Definition

Class:
TrainDispatch
Method:
maximumProfit
Parameters:
String[]
Returns:
int
Method signature:
int maximumProfit(String[] param0)
(be sure your method is public)

Constraints

    Examples


      This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
      This problem was used for: