|
| 1 | +```java |
| 2 | + |
| 3 | +import java.util.*; |
| 4 | +import java.io.*; |
| 5 | + |
| 6 | +class Main { |
| 7 | + |
| 8 | + // IO field |
| 9 | + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); |
| 10 | + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); |
| 11 | + static StringTokenizer st = new StringTokenizer(""); |
| 12 | + |
| 13 | + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} |
| 14 | + static String nextToken() throws Exception { |
| 15 | + if(!st.hasMoreTokens()) nextLine(); |
| 16 | + return st.nextToken(); |
| 17 | + } |
| 18 | + static int nextInt() throws Exception { return Integer.parseInt(nextToken()); } |
| 19 | + static long nextLong() throws Exception { return Long.parseLong(nextToken()); } |
| 20 | + static double nextDouble() throws Exception { return Double.parseDouble(nextToken()); } |
| 21 | + static void bwEnd() throws Exception {bw.flush();bw.close();} |
| 22 | + |
| 23 | + // Additional field |
| 24 | + |
| 25 | + static int K; |
| 26 | + static int[] A, B; |
| 27 | + |
| 28 | + public static void main(String[] args) throws Exception { |
| 29 | + |
| 30 | + for(int T=nextInt();T-->0;) { |
| 31 | + |
| 32 | + ready(); |
| 33 | + solve(); |
| 34 | + } |
| 35 | + |
| 36 | + bwEnd(); |
| 37 | + |
| 38 | + } |
| 39 | + |
| 40 | + static void ready() throws Exception{ |
| 41 | + |
| 42 | + K = nextInt(); |
| 43 | + A = new int[K]; |
| 44 | + B = new int[K]; |
| 45 | + for(int i=0;i<K;i++) A[i] = nextInt(); |
| 46 | + for(int i=0;i<K;i++) B[i] = nextInt(); |
| 47 | + |
| 48 | + } |
| 49 | + |
| 50 | + static void solve() throws Exception{ |
| 51 | + |
| 52 | + int min = 0; |
| 53 | + int[] cntA = new int[100001]; |
| 54 | + int[] cntB = new int[100001]; |
| 55 | + for(int i=0;i<K;i++) { |
| 56 | + cntA[A[i]]++; |
| 57 | + cntB[B[i]]++; |
| 58 | + } |
| 59 | + for(int i=0;i<=100000;i++) { |
| 60 | + int com = Math.min(cntA[i], cntB[i]); |
| 61 | + min += com * i; |
| 62 | + min += (Math.max(cntA[i], cntB[i]) - com) * i; |
| 63 | + } |
| 64 | + |
| 65 | + int max = 0; |
| 66 | + for(int i=0;i<K;i++) for(int j=0;j<K;j++) max += Math.min(B[i], A[j]); |
| 67 | + |
| 68 | + bw.write("Minimalni budova obsahuje " + min + " kostek, "); |
| 69 | + bw.write("maximalni " + max + " kostek.\n"); |
| 70 | + |
| 71 | + } |
| 72 | + |
| 73 | +} |
| 74 | + |
| 75 | +``` |
0 commit comments