Sort by

recency

|

352 Discussions

|

  • + 0 comments

    The problem state that the sweetness have to be greater than k But there's a test where the last sweet is exactly k and it still consider valid, not return -1 What do you even mean?

  • + 0 comments

    def cookies(k,A): # convert list A to priority queue heapq heapq.heapify(A)

    iteration = 0
    while any(c < k for c in A) and len(A) > 1:
        mix = heapq.heappop(A) + 2 * heapq.heappop(A)
        heapq.heappush(A,mix)
        iteration += 1
    
    
    if not all(c >= k for c in A):
        return -1
    
    return iteration
    
  • + 0 comments

    def cookies(k, A): A.sort(reverse = True) queue = [] mixes = 0 while True: if len(A) <= 1 and queue: A = queue[::-1] + A queue = [] if not A and not queue: return mixes if queue: if A[-1] <= queue[0]: last_num = A.pop() else: last_num = queue.pop(0) else: last_num = A.pop() if last_num >= k: next elif len(A) == 0 and last_num < k: return -1 else: if not queue: sec_num = A.pop() else: if A[-1] <= queue[0]: sec_num = A.pop() else: sec_num = queue.pop(0) new_num = last_num + 2 * sec_num queue.append(new_num) mixes += 1

  • + 0 comments

    Is it a good idea to use it for my content based website of cookieclickerunblocked, I'm running this website on WordPress right now, Please give me a honest advice. Thanks

  • + 0 comments
    import java.io.*;
    import java.util.*;
    
    public class Solution {
    
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int numCookies = sc.nextInt();
            int minSweetness = sc.nextInt();
            int count = 0;
            PriorityQueue < Integer> he = new PriorityQueue(numCookies);
            for(int i = 0; i  <  numCookies; i++){
                int sweetness = sc.nextInt();
                he.add(sweetness);
            }
            while(he.peek()  <  minSweetness && he.size() > 1){
                int ne = he.poll() + 2*he.poll();
                he.add(ne);
                count++;
            }
            if(he.peek() >= minSweetness){
                System.out.println(count);
            } else{
                System.out.println(-1);
            }
        }
    }