Tap here to switch tabs
Problem
Submissions

Problem: Maximize Grid Happiness

med
30 min
Try to solve the Maximize Grid Happiness problem.

Statement

You are given four integers m, n, introvertsCount, and extrovertsCount. You have an m $ imes$ n grid, and there are two types of people: introverts and extroverts. There are at most introvertsCount introverts and extrovertsCount extroverts available to be placed on the grid.

You may place at most one person in each cell of the grid, or leave the cell empty. You do not need to place everyone.

The happiness of each person on the grid is determined as follows:

  • An introvert starts with 120120 happiness, but loses 3030 happiness for each placed neighbor sharing a vertically or horizontally adjacent cell.

  • An extrovert starts with 4040 happiness, and gains 2020 happiness for each placed neighbor sharing a vertically or horizontally adjacent cell.

The total grid happiness is the sum of the happiness of all individuals placed on the grid.

Return the maximum possible grid happiness.

Constraints:

  • 1≤1 \leq m, n ≤5\leq 5

  • 0≤0 \leq introvertsCount, extrovertsCount ≤min⁡(\leq \min(m $ imes$ n, 6)6)

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximize Grid Happiness

med
30 min
Try to solve the Maximize Grid Happiness problem.

Statement

You are given four integers m, n, introvertsCount, and extrovertsCount. You have an m $ imes$ n grid, and there are two types of people: introverts and extroverts. There are at most introvertsCount introverts and extrovertsCount extroverts available to be placed on the grid.

You may place at most one person in each cell of the grid, or leave the cell empty. You do not need to place everyone.

The happiness of each person on the grid is determined as follows:

  • An introvert starts with 120120 happiness, but loses 3030 happiness for each placed neighbor sharing a vertically or horizontally adjacent cell.

  • An extrovert starts with 4040 happiness, and gains 2020 happiness for each placed neighbor sharing a vertically or horizontally adjacent cell.

The total grid happiness is the sum of the happiness of all individuals placed on the grid.

Return the maximum possible grid happiness.

Constraints:

  • 1≤1 \leq m, n ≤5\leq 5

  • 0≤0 \leq introvertsCount, extrovertsCount ≤min⁡(\leq \min(m $ imes$ n, 6)6)