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

【题目链接】:http://codeforces.com/contest/754/problem/A

【题解】



求前缀和;

看看pre[n]等于多少;

pre[n]!=0;

则直接整个数组全部输出;

如果pre[n]==0

则在前面找一个i

pre[i]!=0

如果找到了



输出a[1..i]和a[i+1..n];

可以看成是pre[0]=0,pre[i]!=0,pre[n]=0

则可知这两段都是符合要求的不为0;

但是如果没有找到pre[i]!=0

那么就意味着pre[1..n-1]都为0;则数字全为0;则不可能了;

贪心吧。



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; //const int MAXN = x;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int MAXN = 1e2+10; int n,pre[MAXN],len; int main()
{
//freopen("F:\\rush.txt","r",stdin);
rei(n);
rep1(i,1,n)
{
int x;
rei(x);
pre[i] = pre[i-1]+x;
}
if (pre[n]!=0)
{
puts("YES");
puts("1");
printf("%d %d\n",1,n);
}
else
{
int j = -1;
rep1(i,1,n-1)
if (pre[i]!=0)
j = i;
if (j==-1)
puts("NO");
else
{
puts("YES");
puts("2");
printf("%d %d\n",1,j);
printf("%d %d\n",j+1,n);
}
}
return 0;
}

【codeforces 754A】Lesha and array splitting的更多相关文章

  1. 【24.17%】【codeforces 721D】Maxim and Array

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  2. 【Codeforces 258B】 Sort the Array

    [题目链接] http://codeforces.com/contest/451/problem/B [算法] 模拟 在序列中找到一段单调递增的子序列,将这段序列反转,然后判断序列是否变得单调递增,即 ...

  3. 【codeforces 719E】Sasha and Array

    [题目链接]:http://codeforces.com/contest/719/problem/E [题意] 给你一个数列,有两种操作1 l r x 给[l,r]区间上的数加上x, 2 l r 询问 ...

  4. 【44.19%】【codeforces 727C】Guess the Array

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. 【Codeforces 1042D】Petya and Array

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 把a[i]处理成前缀和 离散化. 枚举i从1..n假设a[i]是区间和的a[r] 显然我们需要找到a[r]-a[l]<t的l的个数 即a ...

  6. 【Codeforces 1114B】Yet Another Array Partitioning Task

    [链接] 我是链接,点我呀:) [题意] 让你把数组分成k个连续的部分 使得每个部分最大的m个数字的和最大 [题解] 把原数组降序排序 然后选取前m*k个数字打标记 然后对于原数组 一直贪心地取 直到 ...

  7. Codeforces 754A Lesha and array splitting(简单贪心)

    A. Lesha and array splitting time limit per test:2 seconds memory limit per test:256 megabytes input ...

  8. Codeforces 754A Lesha and array splitting (搜索)

    题目链接 Lesha and array splitting 设s[i][j]为序列i到j的和,当s[i][j]≠0时,即可从i跳到j+1.目标为从1跳到n+1,所以按照题意暴力即可. #includ ...

  9. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

随机推荐

  1. [D3JS] Add more map layer and color

    import React, {Component} from 'react'; import * as d3 from 'd3'; import 'd3-geo'; import * as topoj ...

  2. CSS3制作W3cplus的关注面板

    <!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8& ...

  3. 关于查看域名A记录,MX记录,CNAME记录-NSLOOKUP用法介绍

    关于查看域名A记录,MX记录,CNAME记录-NSLOOKUP用法介绍 用ping查看域名的IP地址,这样只能查到域名的A记录,要查询域名的MX记录.CNAME记录或NS记录,可用nslookup命令 ...

  4. Android 开发之锁屏弹窗

    尝试利用 WindowManager 添加浮窗的方式实现 想在锁屏上面实现弹窗,第一个想法就是利用 WindowManager 设置 Window 的 Flag,通过设置 Flag 的显示优先级来让窗 ...

  5. 26.SpringBoot事务注解详解

    转自:https://www.cnblogs.com/kesimin/p/9546225.html @Transactional spring 事务注解 1.简单开启事务管理 @EnableTrans ...

  6. javascript: with 表单验证

    <html> <head> <script type="text/javascript"> function validate_required ...

  7. ORACLE10g R2【RAC+ASM→RAC+ASM】

    ORACLE10g R2[RAC+ASM→RAC+ASM] 本演示案例所用环境:RAC+ASM+OMF   primary standby OS Hostname node1,node2 dgnode ...

  8. LeetCode Algorithm 05_Longest Palindromic Substring

    Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...

  9. 软件——keil的查找,错误,不能跳转到相应的行

    为什么MDK  keil4.7双击搜索结果不能跳转到相应位置 KEIL搜索的时候双击不跳转到相应的位置 为什么keil点击不能跳转到错误处的问题 在keil中,双击Find In Files中某一行, ...

  10. 常用的Windows命令

    常用的Windows命令 explorer-------打开资源管理器 logoff---------注销命令 shutdown-------关机命令 lusrmgr.msc----本机用户和组 se ...