Question
Hello, Can someone help me explain the purpose of EVERY LINE in this code? And the time complexity and algorithm, and possibly the pseudocode of
Hello, Can someone help me explain the purpose of EVERY LINE in this code? And the time complexity and algorithm, and possibly the pseudocode of it? Thanks! Will give thumbs up
import java.util.*;
import java.io.*;
public class BankQ{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int sum = 0;
while(scanner.hasNextLine()){
String input = scanner.nextLine();
String[] separate = input.split(" ");
int N = Integer.parseInt(separate[0]);
int T = Integer.parseInt(separate[1]);
int amount;
int timeLeft;
Customer[] customer = new Customer[N];
for(int i = 0; i input = scanner.nextLine(); separate = input.split(" "); amount = Integer.parseInt(separate[0]); timeLeft = Integer.parseInt(separate[1]); customer[i] = new Customer(amount, timeLeft); } Arrays.sort(customer); boolean[] taken = new boolean[47]; for( Customer cust: customer) { int closeTime = cust.timeLeft; while (closeTime >= 0) { if(!taken[closeTime]){ sum += cust.amount; taken[closeTime] = true; break; } closeTime--; } } System.out.println(sum); } scanner.close(); } } class Customer implements Comparable int amount, timeLeft; public Customer( int amount, int timeLeft){ this.amount = amount; this.timeLeft = timeLeft; } @Override public int compareTo(Customer customer){ return customer.amount - amount; } } AND here is the prompt to the code if it helps.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started