/* * Solution Template for Shoptimality * * Australian Informatics Olympiad 2023 * * This file is provided to assist with reading of input and writing of output * 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 houses. */ private static int N; /* M is the number of supermarkets. */ private static int M; /* * H contains the locations of the houses. Note that here the houses are * numbered starting from 0. */ private static int H[] = new int[100005]; /* * S contains the locations of the supermarkets. Note that here the * supermarkets are numbered starting from 0. */ private static int S[] = new int[100005]; /* * P contains the price factors of the supermarkets. Note that here the * supermarkets are numbered starting from 0. */ private static int P[] = new int[100005]; /* * answers[i] should store the badness of the best supermarket for the i-th * house. Note that here the houses are numbered starting from 0. */ private static int answers[] = new int[100005]; /* * 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 streams for stdin and stdout. */ BufferedReader input_reader = new BufferedReader(new InputStreamReader( System.in)); BufferedWriter output_writer = new BufferedWriter( new OutputStreamWriter(System.out)); /* Read the values of N, M, H, S and P. */ N = Integer.parseInt(readToken(input_reader)); M = Integer.parseInt(readToken(input_reader)); for (int i = 0; i < N; i++) { H[i] = Integer.parseInt(readToken(input_reader)); } for (int i = 0; i < M; i++) { S[i] = Integer.parseInt(readToken(input_reader)); } for (int i = 0; i < M; i++) { P[i] = Integer.parseInt(readToken(input_reader)); } /* * TODO: This is where you should compute your solution. For each * house, find the badness of the best supermarket, and store these * values into the array answers. */ /* Write the answers. */ for (int i = 0; i < N; i++) { output_writer.write(answers[i] + " "); } output_writer.write("\n"); /* Close the input_reader and output_writer. */ input_reader.close(); output_writer.close(); } }