Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.61 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Set;
  3. import java.util.TreeSet;
  4. import java.util.Iterator;
  5. public class Solution {
  6.  
  7.     public static void main(String[] args) {
  8.         // TODO Auto-generated method stub
  9.         Scanner sc = new Scanner(System.in);
  10.        
  11.         int casos = sc.nextInt();
  12.        
  13.         for(int caso = 1; caso <= casos; caso++) {
  14.             int N = sc.nextInt();
  15.             Set<Pair> tareas = new TreeSet<Pair>();
  16.             for(int i = 0; i < N; i++) {
  17.                 tareas.add(new Pair(sc.nextInt(),sc.nextInt(),i));
  18.                
  19.             }
  20.             Iterator<Pair> it = tareas.iterator();
  21.             Pair[] haciendose = new Pair[2];
  22.             haciendose[0] = it.next();
  23.             haciendose[1] = it.next();
  24.             char[] res = new char[N];
  25.             res[haciendose[0].pos] = 'J';
  26.             res[haciendose[1].pos] = 'C';
  27.             Boolean impossible = false;
  28.             while(it.hasNext() && !impossible) {
  29.                 Pair siguiente = it.next();
  30.                 if(siguiente.v1>=haciendose[0].v2) {
  31.                     haciendose[0] = siguiente;
  32.                     res[siguiente.pos] = 'J';
  33.                 }
  34.                 else if(siguiente.v1>=haciendose[1].v2) {
  35.                     haciendose[1] = siguiente;
  36.                     res[siguiente.pos] = 'C';
  37.                 }
  38.                 else {
  39.                     impossible = true;
  40.                 }
  41.             }
  42.             System.out.println(String.format("Case #%d: %s", caso,impossible?"IMPOSSIBLE":new String(res)));
  43.         }
  44.        
  45.         sc.close();
  46.     }
  47.    
  48.    
  49.  
  50. }
  51.  
  52.  
  53. class Pair implements Comparable<Pair>{
  54.     public Integer v1,v2;
  55.     public Integer pos;
  56.     public Pair(Integer v1, Integer v2,Integer pos) {
  57.         this.v1 = v1;
  58.         this.v2 = v2;
  59.         this.pos = pos;
  60.     }
  61.    
  62.    
  63.     public int compareTo(Pair o) {
  64.         // TODO Auto-generated method stub
  65.         int res = this.v1-o.v1;
  66.         if(res == 0) {
  67.             res = this.v2-o.v2;
  68.         }
  69.         return res;
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement