import java.io.*; import java.util.*; /** * This Wrong Answer submission uses a greedy approach to decide which product * to send to which warehouse. * * Choose the remaining (product, warehouse) pair that minimises the cost to send * all of a remaining product to a remaining warehouse. * * @author Finn Lidbetter */ public class Greedy1 { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] s = br.readLine().split(" "); int w = Integer.parseInt(s[0]); int p = Integer.parseInt(s[1]); long[][] products = new long[w][p]; for (int i=0; i> sortedCosts = new ArrayList<>(); for (int i=0; i costs = new TreeSet<>(); for (int j=0; j { int warehouseNumber; long cost; public WarehouseCost(int id, long c) { warehouseNumber = id; cost = c; } public int compareTo(WarehouseCost w2) { if (cost == w2.cost) { return warehouseNumber - w2.warehouseNumber; } return Long.compare(cost, w2.cost); } }