here below is my code which working for 40 marks but not for 100 marks… i know my program time complexity is near to 10^10 for worst case for 100 marks, but i dont know how to reduce time for my code, what to do further, after looking at editorial, i havn’t understood anything plz help me
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package codechef;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Scanner;
import java.util.TreeSet;
/**
*
* @author Hemant Dhanuka
*/
public class IPCTRAIN1for100Marks {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
// FastReader s = new FastReader();
int totalCases = s.nextInt();
for (int i = 0; i < totalCases; i++) {
int NoOfTrainers = s.nextInt();
int Days = s.nextInt();
boolean DaysAvailablity[] = new boolean[Days];
// LinkedList<Node> l=new LinkedList<>();
// PriorityQueue pq=new PriorityQueue(new MyComparator());
TreeSet pq = new TreeSet(new MyComparator());
for (int j = 0; j < NoOfTrainers; j++) {
int arrivalDay = s.nextInt();
int totalLecutures = s.nextInt();
int Sadness = s.nextInt();
Node jiskoAddkarnaH = new Node(arrivalDay, totalLecutures, Sadness);
pq.add(jiskoAddkarnaH);
}
// System.out.println(pq);
Iterator finalItr = pq.iterator();
long MinimumSadness = 0;
while (finalItr.hasNext()) {
Node Trainee = (Node) finalItr.next();
//System.out.println(Trainee.Sadness);
for (int j = Trainee.arrivalDay; j <= Days && Trainee.totalLecutures > 0; j++) {
if (!DaysAvailablity[j - 1]) {
Trainee.totalLecutures--;
DaysAvailablity[j - 1] = true;
}
}
MinimumSadness += ((long) Trainee.totalLecutures) * Trainee.Sadness;
}
System.out.println(MinimumSadness);
}
}
}
class MyComparator implements Comparator<Object> {
@Override
public int compare(Object o1, Object o2) {
if (((Node) o1).Sadness < ((Node) o2).Sadness) {
return 1;
} else if (((Node) o1).Sadness == ((Node) o2).Sadness) {
if (((Node) o1).arrivalDay >= ((Node) o2).arrivalDay) {
return 1;
}
}
return -1;
}
}
class Node {
int arrivalDay;
int totalLecutures;
int Sadness;
Node(int d, int t, int s) {
this.arrivalDay = d;
this.totalLecutures = t;
this.Sadness = s;
}
}