import java.util.Scanner; import java.util.Stack; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNext()) { int N = in.nextInt(); int capacity = in.nextInt(); int[] order = new int[N]; int[] factor = new int[N]; for (...