public void solve() { try (Scanner scanner = new Scanner(file)) { int T = scanner.nextInt(); for (int t = 1; t <= T; ++t) { int n = scanner.nextInt(); Vector v1 = new Vector(n); for (int i = 0; i < n; ++i) { v1.setCoord(i, scanner.nextLong()); } Vector v2 = new Vector(n); for (int i = 0; i < n; ++i) { v2.setCoord(i, scanner.nextLong()); } long min = 0; v1.sort(); v2.sortReverse(); for (int i = 0; i < n; ++i) { min += v1.getCoord(i) * v2.getCoord(i); } System.out.println("Case #" + t + ": " + min); } } catch (IOException ex) { System.out.println(ex.getMessage()); } }
public double scalarProd(Vector v2) { double val = 0; for (int i = 0; i < coords.length && i < v2.coords.length; ++i) { val += coords[i] * v2.getCoord(i); } return val; }
public Vector2D sub(Vector2D b) { Vector res = super.sub(b); return new Vector2D(res.getCoord(0), res.getCoord(1)); }