8 Route(String[] route) {
9 this.route_name = route[0];
10 this.company_code = route[1];
11 this.full_fare = Integer.parseInt(route[2]);
15 public boolean expensive_than(Route route) {
16 return this.full_fare > route.full_fare;
18 public int fare_difference(Route route) {
19 return Math.abs(this.full_fare - route.full_fare);
21 public boolean operatedByBNB() {
22 return this.company_code.equals(
"BNB");
24 public boolean routeNameStartsWith(String prefix) {
25 return this.route_name.startsWith(prefix);
30 public static void main(String[] args)
throws IOException {
31 InputStreamReader isr =
new InputStreamReader(System.in);
32 BufferedReader br =
new BufferedReader(isr);
33 int remaining_balance = Integer.parseInt(br.readLine());
34 Route first =
new Route(br.readLine().split(
" "));
35 Route second =
new Route(br.readLine().split(
" "));
37 if (remaining_balance >= 1) {
39 if (!first.operatedByBNB() || second.routeNameStartsWith(
"A")) {
41 remaining_balance -= second.full_fare;
42 }
else if (!first.routeNameStartsWith(
"P") & second.expensive_than(first)) {
43 remaining_balance -= first.fare_difference(second);
46 System.out.println(
"The remaining balance is " + remaining_balance +
".");