TopcoderArchive
Archive4 May 2019
TCC19 India Qualifiers

MaxPlanting

Problem statement, definition, constraints, and public examples.

Problem Statement

You are planting some crops in a rectangular field, divided into cells, width by height. Any given cell can have at most one crop growing in it. Any square area of length size can only have at most max crops growing in it. What is the most number of crops that can be grown in the field?

Definition

Class:
MaxPlanting
Method:
most
Parameters:
int, int, int, int
Returns:
int
Method signature:
int most(int width, int height, int size, int max)
(be sure your method is public)

Constraints

  • width will be between 1 and 100, inclusive.
  • height will be between 1 and 100, inclusive.
  • size will be between 1 and MIN(width, height), inclusive.
  • max will be between 1 and 10000, inclusive.

Examples

  1. 3
    3
    2
    1
    Returns: 4
    There are 9 cells in total, but no 2x2 area can have more than one plant. Our best bet is this: X-X --- X-X
  2. 3
    3
    2
    2
    Returns: 6
    Here each 2x2 area can have two crops, so we can do something like this: X-X X-X X-X
  3. 10
    10
    4
    5
    Returns: 42
Back to all problems