## 1. Introduction

In 1935, Hungarian mathematicians Paul Erdős and George Szekeres proved a celebrated theorem, which is now a classic, on relations between lengths of a sequence and its increasing (decreasing) subsequence [

1].

**Theorem** **1.** (Erdős–Szekeres) Supposeand ${x}_{1},{x}_{2},\dots ,{x}_{n}$ is a sequence of real numbers. Then this sequence contains a monotonic increasing (decreasing) subsequence of $a+1$ terms or a monotonic decreasing (increasing) subsequence of $b+1$ terms. More than 85 years have passed since then, and a whole subarea of combinatorics has grown up from the Erdős–Szekeres theorem. Even today we cannot fully appreciate the significance of this theorem, see, for instance, [

2,

3,

4,

5,

6,

7,

8].

The main goal of this paper is to describe the complete family of constraints on the lengths of a sequence, its longest increasing subsequence, and its longest decreasing subsequence.

## 2. Results

**Theorem** **2.** There exists a sequence T of length $n\ge 1$ containing a longest increasing subsequence of length $x=lis\left(T\right)\ge 1$ and a longest decreasing subsequence of length $y=lds\left(T\right)\ge 1$ if and only if the numbers x, y and n satisfy the following conditions: **Proof.** If either $x=1$ or $y=1$ the claim is evident.

In what follows, $x>1,y>1$, and $n>1$.

**Necessity** of the condition (1) immediately follows from the theorem of Erdős–Szekeres. Assume that the condition (1) is not satisfied, i.e., $x\xb7y\le n-1$, then, according to the Erdős–Szekeres theorem, the sequence T of length n contains a monotone increasing subsequence of the length $x+1$ or a monotone decreasing subsequence of the length $y+1$, which contradicts the hypothesis of the theorem. The violation of the condition (2) makes impossible the existence of two subsequences with specified lengths, one of which increases, while the other decreases. In fact, these two subsequences can have no more than one element in common; that is, the sum of their lengths should not exceed $n+1$.

**Sufficiency**. Assume that $x\xb7y\ge n$ and $x+y\le n+1$, and build a sequence T of length n, such that $x=lis\left(T\right),y=lds\left(T\right)$. This sequence is built according to the following scheme. We take a sequence of n natural numbers $1,2,\dots ,n$ and divide it into x groups, in such a way that $T=Concatenation({T}_{1},{T}_{2},\dots ,{T}_{x})$ and satisfies the following conditions:

The numbers in each group are arranged in decreasing order.

All the numbers of a subsequent group are greater than all the numbers of a preceding group.

The first group consists of y elements: $y,y-1,y-2,\dots ,1$, which is possible by the condition $y<n$.

We divide the remaining $n-y$ elements into $x-1$ groups as follows. Let $p=\u230a{\displaystyle \frac{n-y}{x-1}}\u230b$ and $r=(n-y)mod(x-1)$. Note that $p=\u230a{\displaystyle \frac{n-y}{x-1}}\u230b\ge \u230a{\displaystyle \frac{x-1}{x-1}}\u230b=1$ and $0\le r<x-1$. The first r groups represent decreasing subsequences ${T}_{2},\dots ,{T}_{r+1}$ of the length $p+1$:

${T}_{2}=\{y+p+1,y+p,y+p-1,\dots ,y+1\}$

…

${T}_{r+1}=\{y+r(p+1),y+r(p+1)-1,\dots ,y+r(p+1)-p\}$.

The last $x-r-1$ groups represent decreasing subsequences ${T}_{r+2},\dots ,{T}_{x}$ of length p. (If $r=0$, then all $x-1$ decreasing subsequences have the length p):

${T}_{r+2}=\{y+r(p+1)+p,y+r(p+1)+p-1,\dots ,y+r(p+1)+1\}$,

…

${T}_{x}=\{n,n-1,n-2,\dots ,n-p+1\}.$

Before passing to the proof of the sufficiency, we prove the following.

**Claim** **1.** At the partition of $n-y$ elements into $x-1$ groups satisfying Conditions 1–4, the number of elements in each group does not exceed y.

**Proof.** It is given that

$y+p\xb7(x-1)+r=n$. Then,

in accordance with the condition

$x\xb7y\ge n$. Thus

If $r=0$, then all $x-1$ groups are of the same length p and $p\le y$.

If $r>0$, then taking into account that $r<x-1$, and the fact that p and y are positive integers, we conclude with $p+1\le y$, while all the groups are of length p or $p+1$. □

By the above construction and Claim 1, the longest decreasing subsequence in T is the first group and thus has length y, while each longest increasing subsequence is obtained by choosing exactly one element from each of x groups, giving length x. □

**Example** **1.** Consider $n=7,x=4,\phantom{\rule{4pt}{0ex}}\phantom{\rule{4pt}{0ex}}\phantom{\rule{4pt}{0ex}}y=3$, and note that the conditions (1) and (2) are satisfied and $p=\u230a{\displaystyle \frac{n-y}{x-1}}\u230b=3$ and $r=1$. By the construction given in the proof,Clearly, the longest decreasing sequence of T is $(3,2,1)$ and has length $y=3$, and the longest increasing subsequences each have length $x=4$. **Remark** **1.** There are other methods of building sequences satisfying the conditions (1) and (2). For instance, by choosing the last group to be the longest decreasing subsequence rather than the first, or, say, by first creating the group consisting of x increasing integers $n-x+1,n-x+2,\dots ,n$, and then adding $y-1$ increasing groups of nearly equal size so that all the numbers in each group is smaller than the numbers in any previous group.