Login

All Problems

Problem title

Difficulty

Avg time to solve

Increasing Order Search Tree

Easy

15 mins

Minimum days to complete work

Easy

15 mins

Four Keys Keyboard

Moderate

30 mins

Circle of Words

Ninja

63 mins

Check if the door is open or closed

Easy

10 mins

Minimum Sum in matrix

Moderate

15 mins

Count of Matches in Tournament

Easy

20 mins

Grid Value

Moderate

20 mins

Reverse Alternate Nodes of a Singly Linked List

Moderate

--

Game Of Life

Moderate

15 mins

Problem

Submissions

3

Avg. time to solve

20 min

Success Rate

80%

Problem Statement

```
The initial satisfaction of a person of type A is 80. It decreases by 20 for each neighbor.
The initial satisfaction of a person of type B is 50. It increases by 10 for each neighbor.
```

```
You may choose exactly how many people you want to be present in the grid.
The total number of people of type ‘A’ living in the grid can be less than ‘countA’ but cannot exceed ‘countA’. Similarly, total number of people of type ‘B’ living in the grid can be less than ‘countB’ but cannot exceed ‘countB’
A person can live in only one cell.
Not more than one person can live in a cell.
Two cells are said to be neighbors if the cells are adjacent and share a boundary.
```

```
The first line contains an integer ‘T’, which denotes the number of test cases to be run. Then, the ‘T’ test cases follow.
The first and the only line of each test case contains four space-separated integers ‘N’, ‘M’, ‘countA’, and ‘countB’, denoting the grid’s dimensions and the number of each type of people present.
```

```
For each test case, print in a new line an integer denoting the maximum possible grid satisfaction.
```

```
You do not need to print anything. It has already been taken care of. Just implement the given function.
```

```
1 <= T <= 2
1 <= N,M <= 6
0 <= countA, countB <= min(N*M, 6)
Time Limit: 1sec
```

```
1
3 1 0 1
```

```
50
```

```
In this test case, we can have only one person of type B. Since, this person will have no neighbors, the satisfaction of this person will not change and we will get the maximum grid value of 50.
```

```
1
2 2 1 2
```

```
190
```

Console

Sample Test Case

Custom Test Case

Download Test Cases

Test Case 1

Test Case 2

Test Case 3

Saving Code...

Full Screen Mode

Change Language

Change Theme

Solution submission not allowed

Save Code

Reset Code