Cutting Boards

Sort by

recency

|

193 Discussions

|

  • + 0 comments

    Cutting boards are something I use daily, especially when prepping fresh meals, and I’ve realized how much waste can come from kitchen tools over time. That’s why I started paying attention to sustainable fashion brands too — they’ve really inspired me to be more conscious about materials and durability in everything I buy. Choosing products made with eco-friendly practices, whether it’s clothes or kitchen essentials, just feels better and lasts longer. It’s all about making small, thoughtful changes that actually add up in the long run.

  • + 0 comments

    For JS, remember to use BigInt, otherwise, test case 11 will be failed.

    function boardCutting(cost_y, cost_x) {
        // Write your code here
        let sum =BigInt(0);
        let sortedCostX = [...cost_x].toSorted((a,b) => b-a);
        let sortedCostY = [...cost_y].toSorted((a,b) => b-a);
        let px = 0, py = 0;
        while(px < sortedCostX.length && py < sortedCostY.length) {
            if(sortedCostX[px] > sortedCostY[py]) {
                sum += BigInt(py+1) * BigInt(sortedCostX[px]);
                px++;
            } else {
                sum += BigInt(px+1) * BigInt(sortedCostY[py]);
                py++;           
            }
        }
        while(px < sortedCostX.length) {
            sum += BigInt(py+1) * BigInt(sortedCostX[px]);
            px++;
        }    
        while(py < sortedCostY.length) {
            sum += BigInt(px+1) * BigInt(sortedCostY[py]);
            py++;
        }
        return sum % BigInt(10**9+7);
    }
    
  • + 1 comment

    I don't understand the task. I'm already having problems understanding what the input numbers are supposed to represent.

    1
    2 2
    2
    1
    

    what is the 1? 1x1 ? what is 2 2 = 2x2? what's the deal with modulo? don't understand this wild calculation

    but it gets even crazier

    1
    6 4
    2 1 3 1 4
    4 1 2
    

    what are 2 1 3 1 4 and 4 1 2 supposed to be anyway?

  • + 0 comments
    def boardCutting(cost_y, cost_x):
        MOD = 10**9 + 7
        
        # Sort costs in descending order
        cost_y.sort(reverse=True)
        cost_x.sort(reverse=True)
        
        # Variables to track the number of segments
        horizontal_segments = 1
        vertical_segments = 1
        
        total_cost = 0
        
        i, j = 0, 0
        while i < len(cost_y) and j < len(cost_x):
            if cost_y[i] >= cost_x[j]:
                total_cost += cost_y[i] * vertical_segments
                horizontal_segments += 1
                i += 1
            else:
                total_cost += cost_x[j] * horizontal_segments
                vertical_segments += 1
                j += 1
            total_cost %= MOD
        
        # If there are remaining horizontal cuts
        while i < len(cost_y):
            total_cost += cost_y[i] * vertical_segments
            horizontal_segments += 1
            i += 1
            total_cost %= MOD
        
        # If there are remaining vertical cuts
        while j < len(cost_x):
            total_cost += cost_x[j] * horizontal_segments
            vertical_segments += 1
            j += 1
            total_cost %= MOD
        
        return total_cost
    
  • + 0 comments
    #!/bin/python3
    
    import math
    import os
    import random
    import re
    import sys
    
    #
    # Complete the 'boardCutting' function below.
    #
    # The function is expected to return an INTEGER.
    # The function accepts following parameters:
    #  1. INTEGER_ARRAY cost_y
    #  2. INTEGER_ARRAY cost_x
    #
    
    def boardCutting(cost_y, cost_x):
        MOD = 10**9 + 7
        
        # Combine the cost arrays and sort them
        all_costs = sorted([(cost, 'h') for cost in cost_y] + [(cost, 'v') for cost in cost_x], reverse=True)
        
        # Initialize variables
        horizontal_segments = 1
        vertical_segments = 1
        total_cost = 0
        
        # Process each cut in sorted order
        for cost, cut_type in all_costs:
            if cut_type == 'h':
                total_cost = (total_cost + cost * vertical_segments) % MOD
                horizontal_segments += 1
            elif cut_type == 'v':
                total_cost = (total_cost + cost * horizontal_segments) % MOD
                vertical_segments += 1
        
        return total_cost
    
    if __name__ == '__main__':
    
        q = int(input().strip())
    
        for q_itr in range(q):
            first_multiple_input = input().rstrip().split()
    
            m = int(first_multiple_input[0])
    
            n = int(first_multiple_input[1])
    
            cost_y = list(map(int, input().rstrip().split()))
    
            cost_x = list(map(int, input().rstrip().split()))
    
            result = boardCutting(cost_y, cost_x)
            print(result)