<gouthampradhan>greedy_BoatsToSavePeople_1.java
public int numRescueBoats(int[] people, int limit) {
    TreeMap<Integer, Integer> treeMap = new TreeMap<>();
    int boats = 0;
    for (int p : people) {
      treeMap.putIfAbsent(p, 0);
      treeMap.put(p, treeMap.get(p) + 1);
    }
    Arrays.sort(people);
    for (int p : people) {
      if (treeMap.containsKey(p)) {
        int count = treeMap.remove(p);
        --count;
        if (count != 0) {
          treeMap.put(p, count);
        }
        int balance = limit - p;
        Map.Entry<Integer, Integer> floor = treeMap.floorEntry(balance);
        if (floor != null) {
          int c = floor.getValue();
          --c;
          treeMap.remove(floor.getKey());
          if (c != 0) {
            treeMap.put(floor.getKey(), c);
          }
        }
        boats++;
      }
    }
    return boats;
  }
public int sample_funcname ( int [ ] var_0 , int var_1 ) {
  TreeMap < Integer , Integer > var_4 = new TreeMap < > ( ) ;
  int var_6 = 0 ;
  for ( int var_7 : var_0 ) {
    var_4 . putIfAbsent ( var_7 , 0 ) ;
    var_4 . put ( var_7 , var_4 . get ( var_7 ) + 1 ) ;
  }
  Arrays . sort ( var_0 ) ;
  for ( int var_7 : var_0 ) {
    if ( var_4 . containsKey ( var_7 ) ) {
      int var_16 = var_4 . remove ( var_7 ) ;
      -- var_16 ;
      if ( var_16 != 0 ) {
        var_4 . put ( var_7 , var_16 ) ;
      }
      int var_17 = var_1 - var_7 ;
      Map . Entry < Integer , Integer > var_21 = var_4 . floorEntry ( var_17 ) ;
      if ( var_21 != null ) {
        int var_24 = var_21 . getValue ( ) ;
        -- var_24 ;
        var_4 . remove ( var_21 . getKey ( ) ) ;
        if ( var_24 != 0 ) {
          var_4 . put ( var_21 . getKey ( ) , var_24 ) ;
        }
      }
      var_6 ++ ;
    }
  }
  return var_6 ;
}
