其他分享
首页 > 其他分享> > 2020 BIT冬训-贪心 I - Lesha and array splitting CodeForces - 754A

2020 BIT冬训-贪心 I - Lesha and array splitting CodeForces - 754A

作者:互联网

Problem Description

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 liri should satisfy the following conditions:

If there are multiple answers, print any of them.

Examples

Input
3
1 2 -3
Output
YES
2
1 2
3 3
Input
8
9 -12 3 4 -4 -10 7 3
Output
YES
2
1 2
3 8
Input
1
0
Output
NO
Input
4
1 2 3 -5
Output
YES
4
1 1
2 2
3 3
4 4
前缀和
如果数列全部元素的和都不等于0.则输出1个子列,为1~n。
若数列全部元素之和等于0.寻找一个不为0的前缀和。若找到了则输出2个子列1~k,k+1~n。
找不到则是NO。
#include<cstdio>
#include<algorithm>
using namespace std;
int n,a[105],sum,ans;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        sum+=a[i]; 
        if(sum)
            ans=i;
    }
    if(ans==0)
        printf("NO\n");
    else if(sum)
        printf("YES\n1\n1 %d",n);
    else
        printf("YES\n2\n1 %d\n%d %d",ans,ans+1,n);
    return 0;
}

 

 

标签:754A,Lesha,splitting,Input,print,new,array,line
来源: https://www.cnblogs.com/mikku39/p/14396529.html