import java.io.;
import java.util.;

public class BaseballCardProfitCalculator {

    private static Map<String, Integer> marketPrices = new HashMap<>();
    private static List<String> purchasedCards;
    
    public static void main(String[] args) {
        String marketPriceFile = "market-price.txt";
        String priceListFile = "price-list.txt";
        String outputFile = "output.txt";

        // Parse command-line arguments
        for (int i = 0; i < args.length; i++) {
            if (args[i].equals("-m")) {
                marketPriceFile = args[++i];
            } else if (args[i].equals("-p")) {
                priceListFile = args[++i];
            } else if (args[i].equals("-o")) {
                outputFile = args[++i];
            }
        }

        // Load market prices
        try {
            loadMarketPrices(marketPriceFile);
        } catch (IOException e) {
            e.printStackTrace();
            return;
        }
        
        // Compute and output the profits
        try {
            computeProfits(priceListFile, outputFile);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void loadMarketPrices(String filename) throws IOException {
        try (BufferedReader reader = new BufferedReader(new FileReader(filename))) {
            int itemCount = Integer.parseInt(reader.readLine().trim());
            for (int i = 0; i < itemCount; i++) {
                String[] line = reader.readLine().split(" ");
                marketPrices.put(line[0], Integer.parseInt(line[1]));
            }
        }
    }

    private static void computeProfits(String priceListFile, String outputFile) throws IOException {
        try (BufferedReader reader = new BufferedReader(new FileReader(priceListFile));
             PrintWriter writer = new PrintWriter(new FileWriter(outputFile))) {
            
            String line;
            while ((line = reader.readLine()) != null) {
                String[] firstLine = line.split(" ");
                int n = Integer.parseInt(firstLine[0]);
                int w = Integer.parseInt(firstLine[1]);
                
                List<String> cards = new ArrayList<>();
                List<Integer> prices = new ArrayList<>();
                for (int i = 0; i < n; i++) {
                    String[] cardLine = reader.readLine().split(" ");
                    if (!marketPrices.containsKey(cardLine[0])) {
                        System.out.println("Error: Card not found in market prices file.");
                        continue;
                    }
                    cards.add(cardLine[0]);
                    prices.add(Integer.parseInt(cardLine[1]));
                }

                long startTime = System.nanoTime();
                int maxProfit = calculateMaxProfit(cards, prices, w);
                long endTime = System.nanoTime();
                double timeTaken = (endTime - startTime) / 1e9;

                writer.println(n + " " + maxProfit + " " + purchasedCards.size() + " " + timeTaken);
                for (String card : purchasedCards) {
                    writer.println(card);
                }
            }
        }
    }

    private static int calculateMaxProfit(List<String> cards, List<Integer> prices, int w) {
        int maxProfit = 0;
        int numberOfCombinations = 1 << cards.size();
        purchasedCards = new ArrayList<>();
        
        for (int mask = 0; mask < numberOfCombinations; mask++) {
            int totalCost = 0;
            int profit = 0;
            List<String> currentSet = new ArrayList<>();
            
            for (int i = 0; i < cards.size(); i++) {
                if ((mask & (1 << i)) != 0) { // If the i-th item is included
                    String card = cards.get(i);
                    totalCost += prices.get(i);
                    profit += marketPrices.get(card) - prices.get(i);
                    currentSet.add(card);
                }
            }

            if (totalCost <= w && profit > maxProfit) {
                maxProfit = profit;
                purchasedCards = new ArrayList<>(currentSet);
            }
        }

        return maxProfit;
    }
} market-price.txt:
4
HonusWagner1933 2000000
JimRice1975 1000
DerekJeter1996 150
RickyHenderson1983 2000

price-list.txt:
2 300
JimRice1975 100
RickyHenderson1983 150

3 200
HonusWagner1933 202
DerekJeter1996 120
JimRice1975 80 Error: Unable to initialize main class BaseballCardProfitCalculator
Caused by: java.lang.NoClassDefFoundError: IOException correct the errors