CF754A.Lesha and array splitting

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

One spring day on his way to university Lesha found an array A. Lesha likes to split arrays into several parts. This time Lesha decided to split the array A into several, possibly one, new arrays so that the sum of elements in each of the new arrays is not zero. One more condition is that if we place the new arrays one after another they will form the old array A.

Lesha is tired now so he asked you to split the array. Help Lesha!

一个春日,莱沙在去大学的路上发现了一个数组 AA。莱沙喜欢将数组拆分成若干部分。这一次,莱沙决定将数组 AA 拆分为若干(可能仅一个)新数组,使得每个新数组中元素的和均不为零。另一个条件是:若将这些新数组依次拼接起来,则恰好构成原数组 AA。

莱沙现在很疲惫,于是请你来完成这个拆分任务。帮帮莱沙吧!

输入格式

The first line contains single integer n (1 ≤ n ≤ 100) — the number of elements in the array A.

The next line contains n integers _a_1, _a_2, ..., a__n ( - 103 ≤ a__i ≤ 103) — the elements of the array A.

第一行包含一个整数 nn(1≤n≤1001 \leq n \leq 100)—— 数组 AA 中的元素个数。

接下来一行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(−103≤ai≤103-10^3 \leq a_i \leq 10^3)—— 数组 AA 的元素。

输出格式

If it is not possible to split the array A and satisfy all the constraints, print single line containing "NO" (without quotes).

Otherwise in the first line print "YES" (without quotes). In the next line print single integer k — the number of new arrays. In each of the next k lines print two integers l__i and r__i which denote the subarray A[l__i... r__i] of the initial array A being the i-th new array. Integers l__i, r__i should satisfy the following conditions:

  • _l_1 = 1
  • r__k = n
  • r__i + 1 = l__i + 1 for each 1 ≤ i < k.

If there are multiple answers, print any of them.

如果无法将数组 AA 分割并满足所有约束条件,则输出一行字符串 "NO"(不带引号)。

否则,第一行输出 "YES"(不带引号);第二行输出一个整数 kk —— 新数组的个数;接下来的 kk 行中,每行输出两个整数 lil_i 和 rir_i,表示初始数组 AA 的子数组 A[li…ri]A[l_i \dots r_i] 构成第 ii 个新数组。整数 lil_i、rir_i 应满足以下条件:

  • l1=1l_1 = 1
  • rk=nr_k = n
  • 对每个 1≤i<k1 \le i < k,有 ri+1=li+1r_i + 1 = l_{i+1}。

若存在多个合法答案,输出任意一个即可。

输入输出样例

  • 输入#1

    3
    1 2 -3

    输出#1

    YES
    2
    1 2
    3 3
  • 输入#2

    8
    9 -12 3 4 -4 -10 7 3

    输出#2

    YES
    2
    1 2
    3 8
  • 输入#3

    1
    0

    输出#3

    NO
  • 输入#4

    4
    1 2 3 -5

    输出#4

    YES
    4
    1 1
    2 2
    3 3
    4 4

输入解题思路,AI测评打分。不知道怎么写?

首页