TopcoderArchive
Archive
Algorithm problem

SortingPhotos

Problem statement, definition, constraints, and public examples.

Problem Statement

You have a lot of photos on your computer and you would like to sort them into three categories: small, average and large.

A photo of size W1xH1 is considered smaller than a photo of size W2xH2 if W1 < W2 and H1 < H2.

A photo is called small if it is smaller than at least one other photo, and no photo is smaller than it. A photo is called large if it is not smaller than any other photo, and there is at least one photo that is smaller than it. A photo that is neither small nor large is called average.

You are given int[]s W and H that describe your collection of photos. The i-th photo has size W[i]xH[i]. Return a int[] containing exactly three elements - the number of small photos, the number of average photos and the number of large photos in your collection, in this order.

Definition

Class:
SortingPhotos
Method:
sortPhotos
Parameters:
int[], int[]
Returns:
int[]
Method signature:
int[] sortPhotos(int[] W, int[] H)
(be sure your method is public)

Constraints

  • W will contain between 1 and 50 elements, inclusive.
  • H will contain between 1 and 50 elements, inclusive.
  • W and H will contain the same number of elements.
  • Each element of W will be between 1 and 1000, inclusive.
  • Each element of H will be between 1 and 1000, inclusive.

Examples

  1. {1,2,3}
    {1,2,3}
    Returns: {1, 1, 1 }
    The first photo is small, the second one is average, the last one is large.
  2. {1,2,3}
    {3,2,1}
    Returns: {0, 3, 0 }
    In this case no photo is smaller than another, so all photos are average.
  3. {1, 2, 3, 3}
    {1, 2, 3, 3}
    Returns: {1, 1, 2 }
    Note that there can be multiple photos of equal size.
  4. {1, 1, 2, 3}
    {1, 1, 2, 3}
    Returns: {2, 1, 1 }
  5. {1, 2, 2, 3}
    {1, 2, 2, 3}
    Returns: {1, 2, 1 }
Back to all problems