import java.util.Scanner; import java.util.TreeMap; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author drevenak3 */ public class Stavitel { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int k; for(int i = 0; i < n; i++){ TreeMap st1=new TreeMap(); TreeMap st2=new TreeMap(); k = scan.nextInt(); int levels=0; int x = 0; int c; for (int j = 0; j < k; j++) { c=scan.nextInt(); if(st1.containsKey(c)){ x = st1.get(c); st1.remove(c); st1.put(c,x+1); }else{ st1.put(c,1); } if(c>levels) levels = c; } for (int j = 0; j < k; j++) { c=scan.nextInt(); if(st2.containsKey(c)){ x = st2.get(c); st2.remove(c); st2.put(c,x+1); }else{ st2.put(c,1); } if(c>levels) levels = c; } int max=0; int pl1=0; int pl2=0; for (int j = 1; j <= levels; j++) { pl1=0; for (Integer p:st1.keySet()) { if(p>=j){ pl1+=st1.get(p); } } pl2=0; for (Integer p:st2.keySet()) { if(p>=j){ pl2+=st2.get(p); } } max+=pl1*pl2; } int min =0,m1,m2; for(int j =1; j<= levels; j++){ m1=0; if(st1.containsKey(j)) m1=st1.get(j); m2=0; if(st2.containsKey(j)) m2=st2.get(j); min += Math.max(m1,m2)*j; } System.out.printf("Minimalni budova obsahuje %d kostek, maximalni %d kostek.\n",min,max); } } }