/* * Solution Template for Shoptimality * * Australian Informatics Olympiad 2023 * * 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. */ #include /* N is the number of houses. */ int N; /* M is the number of supermarkets. */ int M; /* * H contains the locations of the houses. Note that here the houses are * numbered starting from 0. */ int H[100005]; /* * S contains the locations of the supermarkets. Note that here the * supermarkets are numbered starting from 0. */ int S[100005]; /* * P contains the price factors of the supermarkets. Note that here the * supermarkets are numbered starting from 0. */ int P[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. */ int answers[100005]; int main(void) { /* Open the input and output files. */ FILE *input_file = fopen("shopin.txt", "r"); FILE *output_file = fopen("shopout.txt", "w"); /* Read the values of N, M, H, S and P from input file. */ fscanf(input_file, "%d%d", &N, &M); for (int i = 0; i < N; i++) { fscanf(input_file, "%d", &H[i]); } for (int i = 0; i < M; i++) { fscanf(input_file, "%d", &S[i]); } for (int i = 0; i < M; i++) { fscanf(input_file, "%d", &P[i]); } /* * 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 to the output file. */ for (int i = 0; i < N; i++) { fprintf(output_file, "%d ", answers[i]); } /* Finally, close the input/output files. */ fclose(input_file); fclose(output_file); return 0; }