public int minimalFatigue(int[] magicalGirlStrength, int[] enemyStrength,
			int[] enemyCount) {

		// log(n)
		HashMap<Integer, Integer> hashMap = new HashMap<Integer, Integer>();
		Arrays.sort(magicalGirlStrength);

		int total = 0;
		for (int i = 0; i < enemyStrength.length; i++) {
			Integer value = hashMap.get(enemyStrength[i]);
			if (value == null) {
				value = 0;
			}
			value += enemyCount[i];
			hashMap.put(enemyStrength[i], value);
			total += enemyCount[i];
		}
		Integer[] keys = hashMap.keySet().toArray(new Integer[0]);
		Arrays.sort(keys);
		reverse(keys);
		// O(50*50*100)=O(250000)
		for (int t = 1;; t++) {
			boolean hit = false;
			// O(50)
			for (int i = 0; i < magicalGirlStrength.length; i++) {

				// O(50*100)

				for (Integer key : keys) {
					if (hashMap.get(key) > 0
							&& key <= magicalGirlStrength[i]) {
						hashMap.put(key, hashMap.get(key) - 1);
						total--;
						if (total == 0) {
							return t;
						}
						hit = true;
						break;
					}
				}
			}
			if (!hit) {
				return -1;
			}
		}

	}