daily pastebin goal
31%
SHARE
TWEET

Untitled

a guest Aug 21st, 2018 56 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
  1. public class Solution {
  2.     public int nchoc(int A, ArrayList<Integer> B) {
  3.         TreeMap<Integer, Integer> bags = new TreeMap<Integer, Integer>();
  4.         long res = 0;
  5.         int mod = (int) (Math.pow(10, 9)) + 7;
  6.         for (int i = 0; i < B.size(); i++) {
  7.             int key = B.get(i);
  8.             if (bags.containsKey(key)) {
  9.                 int val = bags.get(key) + 1;
  10.                 bags.put(key, val);
  11.             }
  12.             else
  13.                 bags.put(key, 1);
  14.         }
  15.         for (int i = 0; i < A; i++) {
  16.             int chocos = bags.lastKey();
  17.             int val = bags.get(chocos) - 1;
  18.             if (val == 0)
  19.                 bags.remove(chocos);
  20.             else
  21.                 bags.put(chocos/2, val);
  22.             res = ((res%mod) + (chocos%mod))%mod;
  23.         }
  24.         return res%mod;
  25.     }
  26. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top