754A.md (1848B)
1 Source: https://codeforces.com/problemset/problem/754/A 2 3 A. Lesha and array splitting 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 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*. 22 23 Lesha is tired now so he asked you to split the array. Help Lesha! 24 25 Input 26 27 The first line contains single integer *n* (1 ≤ *n* ≤ 100) — the number of elements in the array *A*. 28 29 The next line contains *n* integers *a*1, *a*2, ..., *a**n* ( - 103 ≤ *a**i* ≤ 103) — the elements of the array *A*. 30 31 Output 32 33 If it is not possible to split the array *A* and satisfy all the constraints, print single line containing "NO" (without quotes). 34 35 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: 36 37 * *l*1 = 1 38 * *r**k* = *n* 39 * *r**i* + 1 = *l**i* + 1 for each 1 ≤ *i* < *k*. 40 41 If there are multiple answers, print any of them. 42 43 Examples 44 45 Input 46 47 ``` 48 3 49 1 2 -3 50 ``` 51 52 Output 53 54 ``` 55 YES 56 2 57 1 2 58 3 3 59 ``` 60 61 Input 62 63 ``` 64 8 65 9 -12 3 4 -4 -10 7 3 66 ``` 67 68 Output 69 70 ``` 71 YES 72 2 73 1 2 74 3 8 75 ``` 76 77 Input 78 79 ``` 80 1 81 0 82 ``` 83 84 Output 85 86 ``` 87 NO 88 ``` 89 90 Input 91 92 ``` 93 4 94 1 2 3 -5 95 ``` 96 97 Output 98 99 ``` 100 YES 101 4 102 1 1 103 2 2 104 3 3 105 4 4 106 ```