CHPLGNS - Editorial

I did the same thing, but I am getting WA for most of the cases. Although few cases are accepted. Please someone tell me what is wrong with my solution- CodeChef: Practical coding for everyone

pls help me why I am getting nZEC for the following code

import java.io.IOException;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.Map;

public class Main {

public static void main(String[] args) throws IOException  {
    Scanner sc = new Scanner(System.in);
     int t = sc.nextInt();
     while(t-->0)
     {
        Main ob = new Main();
        ob.disp();
     }
}
void disp()throws IOException
{
   Scanner in = new Scanner(System.in);  
   int n =in.nextInt();
   TreeMap<Integer,Integer> tm = new TreeMap<>();
   int i =0;
   int [] ans= new int[n];
   int l = n;
   while(n-->0)
   {
       int min =1000008;
       int m = in.nextInt();
       i++;
       while(m-->0)
       {
          int x =in.nextInt(); 
           int y =in.nextInt();
           min = Math.min(min,x);
       }
       tm.put(min,i);
   }
   int r=l-1;
  
   for(Map.Entry<Integer,Integer> entry: tm.entrySet())
   {
       int k= entry.getValue();
        System.out.println(k);
      ans[k-1]= r;
      r--;
   }
   for(int j=0;j<l;j++)
   {
       System.out.print(ans[j]+" ");
   }
    System.out.println();
}

}

What if there are two polygons and first polygon coordinates are (0,0) (1,0) (1,1) and (0,1) and second polygon coordinates are (0,0) (-1,0) (-1,-1) and (0,-1).
So according to your algorithm what I understood is if you sort these two polygons then second polygon which lesser max x coordinate will lie in first polygon but actually its not lying.
Can somebody help me where I am going wrong.

@kartik7153
If you are reading the practice version of this problem then it doesn’t contain enough information in it. Refer to the competition version of the problem description as that has been updated with extra information. Refer to the first paragraph where it states that no two polygons shall intersect with each other so your example isn’t a valid test example. Also polygon P1 is either completely inside another polygon P2 or P2 is completely inside P1. This applies for all polygons. Have a look at the diagram in the problem and you will see that the polygons are all inside of each other, this simplifies the problem a lot.

Also the questions and answers in the competition version of the problem give more explanation which may help you understand the exact constraints for the polygons.

Highest x-coordinate! Wow, never thought of that :slight_smile:

The error was that I did not clear the vector. Thanks sumitjha4321 for pointing the error. It works now.