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
-
😈CP LOL1♥️👧
2 min ago
-
Adult Telegram Channels
5 min ago
-
ddssdf dfsdsf dfs dfsdfs fdssdfdf
15 min ago
-
Untitled
18 min ago
-
sdfa dasf sdfaasdf
20 min ago
-
Untitled
37 min ago
-
CP😈 VIDEOS R@PED😏 TEEN GIRLS👧💦💦
38 min ago
-
Dating with teens
39 min ago
-
Viral Doods
46 min ago
-
CH.L...DP.R.N ..p..ro..n 🍑🐥
46 min ago