Codeforces Round #390 (Div. 2)A

来源:互联网 发布:asp网络程序怎么样? 编辑:程序博客网 时间:2024/05/16 14:48

A. Lesha and array splitting
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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 li, ri should 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
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

#include <bits/stdc++.h>using namespace std;int main(){    int n;    int a[105];    scanf("%d",&n);    int sum=0;    int h=0;    for(int i=0;i<n;i++){        scanf("%d",a+i);        sum+=a[i];        if(a[i]==0){            h++;        }    }    if(sum!=0){        puts("YES");        puts("1");        printf("%d %d\n",1,n);    }    else if(h==n){        puts("NO");    }    else{        int k=0;        int l;        for(int i=0;i<n;i++){            k+=a[i];            if(k!=0){                l=i;                break;            }        }        puts("YES");        puts("2");        printf("%d %d\n",1,l+1);        printf("%d %d\n",l+2,n);    }    return 0;}
0 0
原创粉丝点击