A. Unimodal Array

Codeforces
IDCF831A
Time1000ms
Memory256MB
Difficulty
implementation
English · Original
Chinese · Translation
Formal · Original
Array of integers is _unimodal_, if: * it is strictly increasing in the beginning; * after that it is constant; * after that it is strictly decreasing. The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent. For example, the following three arrays are unimodal: \[5, 7, 11, 11, 2, 1\], \[4, 4, 2\], \[7\], but the following three are not unimodal: \[5, 5, 6, 6, 1\], \[1, 2, 1, 2\], \[4, 5, 5, 6\]. Write a program that checks if an array is unimodal. ## Input The first line contains integer _n_ (1 ≤ _n_ ≤ 100) — the number of elements in the array. The second line contains _n_ integers _a_1, _a_2, ..., _a__n_ (1 ≤ _a__i_ ≤ 1 000) — the elements of the array. ## Output Print "_YES_" if the given array is unimodal. Otherwise, print "_NO_". You can output each letter in any case (upper or lower). [samples] ## Note In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively).
整数数组是_单峰的_,当且仅当: 存在一个下标 $i$,使得序列从第一个元素到第 $i$ 个元素非严格递增,从第 $i$ 个元素到最后一个元素非严格递减。 第一个块(递增)和最后一个块(递减)可以不存在。允许这两个块都不存在。 例如,以下三个数组是单峰的:#cf_span[[5, 7, 11, 11, 2, 1]],#cf_span[[4, 4, 2]],#cf_span[[7]];但以下三个不是单峰的:#cf_span[[5, 5, 6, 6, 1]],#cf_span[[1, 2, 1, 2]],#cf_span[[4, 5, 5, 6]]。 编写一个程序,判断一个数组是否为单峰的。 第一行包含整数 #cf_span[n](#cf_span[1 ≤ n ≤ 100])——数组中元素的个数。 第二行包含 #cf_span[n] 个整数 #cf_span[a1, a2, ..., an](#cf_span[1 ≤ ai ≤ 1 000])——数组的元素。 如果给定数组是单峰的,请输出 "_YES_";否则输出 "_NO_"。 你可以以任意大小写输出每个字母。 在第一个示例中,数组是单峰的,因为从位置 #cf_span[1] 到位置 #cf_span[2](包含)严格递增,从位置 #cf_span[2] 到位置 #cf_span[4](包含)为常数,然后从位置 #cf_span[4] 到位置 #cf_span[6](包含)严格递减。 ## Input 第一行包含整数 #cf_span[n](#cf_span[1 ≤ n ≤ 100])——数组中元素的个数。第二行包含 #cf_span[n] 个整数 #cf_span[a1, a2, ..., an](#cf_span[1 ≤ ai ≤ 1 000])——数组的元素。 ## Output 如果给定数组是单峰的,请输出 "_YES_";否则输出 "_NO_"。你可以以任意大小写输出每个字母。 [samples] ## Note 在第一个示例中,数组是单峰的,因为从位置 #cf_span[1] 到位置 #cf_span[2](包含)严格递增,从位置 #cf_span[2] 到位置 #cf_span[4](包含)为常数,然后从位置 #cf_span[4] 到位置 #cf_span[6](包含)严格递减。
**Definitions** Let $ n \in \mathbb{Z} $ be the length of the array. Let $ A = (a_1, a_2, \dots, a_n) $ be a sequence of integers. **Constraints** 1. $ 1 \leq n \leq 100 $ 2. $ 1 \leq a_i \leq 1000 $ for all $ i \in \{1, \dots, n\} $ **Objective** Determine whether $ A $ is *unimodal*, i.e., there exists an index $ p \in \{1, \dots, n\} $ such that: - $ a_1 \leq a_2 \leq \dots \leq a_p $ (non-decreasing prefix), - $ a_p \geq a_{p+1} \geq \dots \geq a_n $ (non-increasing suffix). The increasing and/or decreasing segments may be empty (i.e., $ p = 1 $ or $ p = n $ is allowed). Output "YES" if such $ p $ exists; otherwise, output "NO".
Samples
Input #1
6
1 5 5 5 4 2
Output #1
YES
Input #2
5
10 20 30 20 10
Output #2
YES
Input #3
4
1 2 1 2
Output #3
NO
Input #4
7
3 3 3 3 3 3 3
Output #4
YES
API Response (JSON)
{
  "problem": {
    "name": "A. Unimodal Array",
    "description": {
      "content": "Array of integers is _unimodal_, if: *   it is strictly increasing in the beginning; *   after that it is constant; *   after that it is strictly decreasing. The first block (increasing) and the las",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF831A"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Array of integers is _unimodal_, if:\n\n*   it is strictly increasing in the beginning;\n*   after that it is constant;\n*   after that it is strictly decreasing.\n\nThe first block (increasing) and the las...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "整数数组是_单峰的_,当且仅当:\n\n存在一个下标 $i$,使得序列从第一个元素到第 $i$ 个元素非严格递增,从第 $i$ 个元素到最后一个元素非严格递减。\n\n第一个块(递增)和最后一个块(递减)可以不存在。允许这两个块都不存在。\n\n例如,以下三个数组是单峰的:#cf_span[[5, 7, 11, 11, 2, 1]],#cf_span[[4, 4, 2]],#cf_span[[7]];但以下三...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z} $ be the length of the array.  \nLet $ A = (a_1, a_2, \\dots, a_n) $ be a sequence of integers.\n\n**Constraints**  \n1. $ 1 \\leq n \\leq 100 $  \n2. $ 1 \\leq a_i \\le...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments