import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author cteam084 */ class Stavitel { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); int cases = 0; int matrix[][]; for (int i = 0; i < cases; i++) { int matrixsize = Integer.parseInt(br.readLine()); matrix = new int[matrixsize][matrixsize]; for (int j = 0; j < matrixsize; j++) { for (int k = 0; k < matrixsize; k++) { matrix[j][k] = 0; } } int infox[] = new int[matrixsize]; int infoy[] = new int[matrixsize]; String[] nums = br.readLine().split(" "); String[] nums2 = br.readLine().split(" "); for (int j = 0; j < matrixsize; j++) { infox[j] = Integer.parseInt(nums[j]); infoy[j] = Integer.parseInt(nums2[j]); } int maxcubes = 0; for (int j = 0; j < matrixsize; j++) { if(infox[j] >= infoy[j]) maxcubes+= infoy[j]; else maxcubes += infox[j]; } int tmpx[] = new int[matrixsize]; int tmpy[] = new int[matrixsize]; int counter = 0; for (int r = 0; r < matrixsize; r++) { for (int c = 0; c < matrixsize; c++) { if(infoy[r] == infox[c] && !contain(tmpy, tmpx[c]) && infoy[r] != 0) { matrix[r][c] = infoy[r]; tmpx[counter] = c; tmpy[counter] = r; counter++; break; } else { if(infoy[r] < infox[c] && !contain(tmpy, tmpx[c]) && infoy[r] != 0) { matrix[r][c] = infoy[r]; tmpx[counter] = c; tmpy[counter] = r; } counter++; } } } for (int j = 0; j < matrixsize; j++) { if(!contain(infox, j)) { for (int k = 0; k < matrixsize; k++) { if(infoy[k] == infox[j] && infox[j] != 0 && !contain(tmpx, k)) { matrix[j][k] = infox[j]; tmpx[counter] = j; tmpy[counter] = k; counter++; break; } else { if(infoy[k] < infox[j] && !contain(tmpx, tmpx[k]) && infox[j] != 0) { matrix[j][k] = infox[j]; tmpx[counter] =j; tmpy[counter] = k; } counter++; } } } } int min = 0; for (int j = 0; j < matrixsize; j++) { for (int k = 0; k < matrixsize; k++) { min += matrix[i][j]; } } bw.write("Minimalni budova obsahuje " + min + " kostek, maximalni " + maxcubes + " kostek."); } bw.flush(); } public static boolean contain(int [] f,int v) { for (int i = 0; i < f.length; i++) { if(f[i] == v) return true; } return false; } }