import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; 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++){ ArrayList st1=new ArrayList(); ArrayList st2=new ArrayList(); k = scan.nextInt(); for (int j = 0; j < k; j++) { st1.add(scan.nextInt()); } for (int j = 0; j < k; j++) { st2.add(scan.nextInt()); } int m1=maxim(st1); int m2=maxim(st1); int levels=m1>m2?m1:m2; int max=0; for (int j = 1; j <= levels; j++) { int pl1=0; for (int l = 0; l < st1.size(); l++) { if(st1.get(l)>=j){ pl1++; } } int pl2=0; for (int l = 0; l < st2.size(); l++) { if(st2.get(l)>=j){ pl2++; } } max+=pl1*pl2; } TreeMap m=new TreeMap(); Arrays.sort(st2.toArray()); for (int j = 0; j < st2.size(); j++) { int c=st2.get(j); ++j; int pc=1; while(jm.get(c)){ m.remove(c); m.put(c, pc); } }else{ m.put(c, pc); } } int min=0; for (Integer p:m.keySet()) { min+=p*m.get(p); } System.out.printf("Minimalni budova obsahuje %d kostek, maximalni %d kostek.\n",min,max); } } public static int maxim(ArrayList p){ int max=p.get(0); for (int i = 0; i < p.size(); i++) { if(p.get(i)>max) max=p.get(i); } return max; } }