/* * Solution Template for Backpacking * * Australian Informatics Olympiad 2024 * * This file is provided to assist with reading and writing of the input * files for the problem. You may modify this file however you wish, or * you may choose not to use this file at all. */ import java.io.*; class Solution { /* N is the number of towns. */ private static int N; /* K is the maximum number of cans that Norman can fit in his backpack. */ private static int K; /* * D contains the distances between the towns. Note that the array starts * from 0, and so the values are D[0] to D[N-2]. */ private static int D[] = new int[200005]; /* * C contains the cost of food in each town. Note that the array starts * from 0, and so the values are C[0] to C[N-1]. */ private static int C[] = new int[200005]; private static int answer; /* * Read the next token from the input file. * Tokens are separated by whitespace, i.e., spaces, tabs and newlines. * If end-of-file is reached then an empty string is returned. */ private static String readToken(BufferedReader in) throws IOException { StringBuffer ans = new StringBuffer(); int next; /* Skip any initial whitespace. */ next = in.read(); while (next >= 0 && Character.isWhitespace((char)next)) next = in.read(); /* Read the following token. */ while (next >= 0 && ! Character.isWhitespace((char)next)) { ans.append((char)next); next = in.read(); } return ans.toString(); } public static void main(String[] args) throws IOException { /* Open the input and output files. */ BufferedReader input_file = new BufferedReader(new FileReader( "backin.txt")); BufferedWriter output_file = new BufferedWriter(new FileWriter( "backout.txt")); /* Read the values of N, K, D, and C from the input file. */ N = Integer.parseInt(readToken(input_file)); K = Integer.parseInt(readToken(input_file)); for (int i = 0; i < N-1; i++) { D[i] = Integer.parseInt(readToken(input_file)); } for (int i = 0; i < N; i++) { C[i] = Integer.parseInt(readToken(input_file)); } /* * TODO: This is where you should compute your solution. Store the * minimum total amount that Norman must spend into the variable answer. */ /* Write the answer to the output file. */ output_file.write(answer + "\n"); /* Finally, close the input/output files. */ input_file.close(); output_file.close(); } }