TopcoderARCHIVE
Archive/Problems/SlowSequence
TCO · Problem 16496

SlowSequence

Problem statement, definition, constraints, and public examples.

Problem Statement

A slow sequence is a sequence A of N elements with the following properties:

  • A[0] = 0
  • for each valid i, the values A[i] and A[i+1] differ by exactly 1

Given N and S, construct and return any slow sequence with sum S. Return an empty int[] if such a sequence does not exist.

Definition

Class:
SlowSequence
Method:
construct
Parameters:
int, int
Returns:
int[]
Method signature:
int[] construct(int N, int S)
(be sure your method is public)

Constraints

  • N will be between 1 and 2500, inclusive.
  • S will be between -10^9 and 10^9, inclusive.

Examples

  1. 4
    4
    Returns: {0, 1, 2, 1 }
    The sequence {0, 1, 2, 1} has all the desired properties: element 0 is 0, we have |0-1| = |1-2| = |2-1| = 1, and its sum is 0+1+2+1 = 4.
  2. 8
    0
    Returns: {0, 1, 0, -1, 0, -1, 0, 1 }
  3. 1
    4700
    Returns: { }
  4. 5
    -10
    Returns: {0, -1, -2, -3, -4 }
← All problems