A. Lesha and array splitting

来源:互联网 发布:大连淘宝美工学校 编辑:程序博客网 时间:2024/06/05 00:35

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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!

Input

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

The next line contains n integers a1, a2, ..., an ( - 103 ≤ ai ≤ 103) — the elements of the array A.

Output

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 li and ri which denote the subarray A[li... ri] of the initial array A being the i-th new array. Integers lirishould satisfy the following conditions:

  • l1 = 1
  • rk = n
  • ri + 1 = li + 1 for each 1 ≤ i < k.

If there are multiple answers, print any of them.

Examples
input
31 2 -3
output
YES21 23 3
input
89 -12 3 4 -4 -10 7 3
output
YES21 23 8
input
10
output
NO
input
41 2 3 -5
output
YES41 12 23 34 4


解题说明:此题是一道水题,只需要保证数组中每一段不为0即可,首先判断数组和是否为0,如果不为0直接满足条件,否则判断是否每个数都为0,不是至少可以分为2段。


#include<cstdio>#include<algorithm>#include<cstring>#include<cstdlib>#include<iostream>using namespace std;int main(){int n, i, a[100], sum = 0;scanf ("%d", &n);for (i = 0; i < n; i++) {scanf ("%d", &a[i]);sum += a[i];}if (sum != 0){printf ("YES\n1\n1 %d", n);}else {for (i = 0; i < n && a[i] == 0; i++);if (i == n){printf ("NO\n");}else{printf ("YES\n2\n%d %d\n%d %d\n", 1, i + 1, i + 2, n);}}return 0;}


0 0
原创粉丝点击