Risha
Never
import java.util.*; class ComicBook implements Comparable<ComicBook> { String name; int price; public ComicBook(String name, int price) { this.name = name; this.price = price; } @Override public int compareTo(ComicBook other) { if (this.price == other.price) { return this.name.compareTo(other.name); } return Integer.compare(this.price, other.price); } } public class ComicBookPurchase { public static void findComicBookPairs(int N, int X, String[] names, int[] prices) { ComicBook[] comicBooks = new ComicBook[N]; for (int i = 0; i < N; i++) { comicBooks[i] = new ComicBook(names[i], prices[i]); } Arrays.sort(comicBooks); List<ComicBook> purchasedComics = new ArrayList<>(); for (int i = 0; i < N - 1; i += 2) { int totalPrice = comicBooks[i].price + comicBooks[i + 1].price; if (totalPrice <= X) { X -= totalPrice; purchasedComics.add(comicBooks[i]); purchasedComics.add(comicBooks[i + 1]); } } if (purchasedComics.isEmpty()) { System.out.println("NONE"); } else { for (ComicBook comic : purchasedComics) { System.out.println(comic.name + " - " + comic.price); } } } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int N = scanner.nextInt(); int X = scanner.nextInt(); scanner.nextLine(); // Consume the remaining newline character String[] names = new String[N]; for (int i = 0; i < N; i++) { names[i] = scanner.nextLine(); } int[] prices = new int[N]; String[] priceStr = scanner.nextLine().split(" "); for (int i = 0; i < N; i++) { prices[i] = Integer.parseInt(priceStr[i]); } findComicBookPairs(N, X, names, prices); } }
Raw Text
-
Pedowoman boy
2 min ago
-
C..P V.I.D..E.O.S
2 min ago
-
πππ NEW CP UPDATE MAY 2024 VIDEOS WORKING ALL FREE FOLDER πππ
3 min ago
-
CPπ LOL1ππ§ FOLDERSπ―π
16 min ago
-
Untitled
30 min ago
-
+2347049440188"" I want to join occult for money and power ritual,,call the spiritual grandmaster of
C++ | 33 min ago
-
+2347049440188"" I want to join occult for money and power ritual,,call the spiritual grandmaster of
C# | 34 min ago
-
+2347049440188"" I want to join occult for money and power ritual,,call the spiritual grandmaster of
C++ | 35 min ago
-
+2347049440188"" I want to join occult for money and power ritual,,call the spiritual grandmaster of
C++ | 36 min ago
-
+2347049440188"" I want to join occult for money and power ritual,,call the spiritual grandmaster of
C++ | 37 min ago