FGFS - Editorial

If you want to do it in C you’ll have to write your own code, but I suggest you start using C++ with STL, C++11 library is huge and its also the standard.

Shouldn’t it be dp[T]=max(dp[T+1],1+dp[L]); ??

hello :slight_smile: the main differences I can see between both of our solutions is the type used to store the answer… I’ve used long long :slight_smile:

EDIT: After changing the data types I now get TLE veredict with your code… Try to encapsulate the main procedure to get the answer on a separate function… It’s easier to debug and spot bottlenecks :slight_smile:

I am struggling to find error in this code of mine from past 2 hours, it gives segmentation fault and I am not able to see any reason for that. Can anyone please help.
https://www.codechef.com/viewsolution/29699503

Thanks man! Changing K size array to a map get my solution accepted. :smiley:
https://www.codechef.com/viewsolution/31994049

I used a vector of priority queues to maintain the increasing order of the finishing times. Then I extracted the top and checked whether it overlaps with the previous interval. If not then I increase the count. Somehow I am getting a TLE message. I just want to know how can I further improve the efficiency.
Here’s my code: CodeChef: Practical coding for everyone
Any help would be appreciated.
Thank you :smiley:

What is the problem with this solution? It is passing test cases but I am getting the wrong answer in hidden test cases. Someone, please help.
class Codechef
{
public static void SortArray(int[] arr, int[] depar,int[] pref,int n){
for(int i=0;i<n-1;i++){
if(arr[i]>arr[i+1]){
// sorting arrival time
int temp = arr[i];
arr[i]=arr[i+1];
arr[i+1]=temp;
// sorting departure time
int dep=depar[i];
depar[i]=depar[i+1];
depar[i+1]=dep;

                                    // sorting preferences array
                                    int pre=pref[i];
                                    pref[i]=pref[i+1];
                                    pref[i+1]=pre;
                                }
                            }
                        }
                        public static void Apetite(int[] arr,int[] depar,int[] pref,int k, int n){
                            Map<Integer,Boolean> occupied = new HashMap<>();
                            int count=0,keep_in=-1;
                            for(int i=0;i<n;i++){
                                if(!occupied.containsKey(pref[i])){
                                    occupied.put(pref[i],false);
                                }
                                if(!occupied.get(pref[i])){
                                    count++; keep_in++;
                                    occupied.replace(pref[i],true);
                                }else{
                                    if(arr[i]>=depar[keep_in]){
                                        count++; keep_in++;
                                    }
                                }
                            }
                            System.out.println(count);
                        }
                        public static void main(String[] args) throws java.lang.Exception {
                            Scanner sc = new Scanner(System.in);
                            int n=sc.nextInt(); int k=sc.nextInt();
                            int[] arr = new int[n]; int[] depar = new int[n];
                            int[] pref = new int[n];
                            for(int i=0;i<n;i++){
                                arr[i]=sc.nextInt(); depar[i]=sc.nextInt();
                                pref[i]=sc.nextInt();
                            }
                            SortArray(arr,depar,pref,n);
                            Apetite(arr,depar,pref,k,n);
                        }
                    }