File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
contest/src/main/java/com/github/contest/heap Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -217,3 +217,27 @@ fun numberGame(nums: IntArray): IntArray {
217
217
218
218
return nums
219
219
}
220
+
221
+ /* *
222
+ * 2335. Minimum Amount of Time to Fill Cups
223
+ */
224
+
225
+ fun fillCups (amount : IntArray ): Int {
226
+ val heap = PriorityQueue <Int > { a, b -> b - a }
227
+ var counter = 0
228
+ for (water in amount) if (water != 0 ) heap.offer(water)
229
+ while (heap.isNotEmpty()) {
230
+ if (heap.size >= 2 ) {
231
+ val one = heap.poll()
232
+ val two = heap.poll()
233
+ if (one - 1 != 0 ) heap.offer(one - 1 )
234
+ if (two - 1 != 0 ) heap.offer(two - 1 )
235
+ } else {
236
+ val single = heap.poll()
237
+ if (single - 1 != 0 ) heap.offer(single - 1 )
238
+ }
239
+ counter++
240
+ }
241
+
242
+ return counter
243
+ }
You can’t perform that action at this time.
0 commit comments