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. 蚂蚁金服入股36Kr给我的一点警示:应该相信自己的理性分析,不能盲目迷信权威

    最近3年,关注互联网和创业投资比较多,每周都会关注下本周发生的创业投融资大事件. 我注意到,一些自媒体作者经常会发布一些有"前瞻性"的文章,比如"美团大众要合并了&quo ...

  2. Hadoop学习小结

    还在学校的时候,就知道Hadoop的存在了. 2012年在公司实习的时候,买了<Hadoop权威指南第2版>,大致看了下. 今年,抽空也大致喵了几眼. 最大的感悟就是:光看不做,还是不行. ...

  3. Eclipse中Git插件使用技巧:[5]还原文件

    如果修改了某个文件并未提交至本地库(add index),那么怎么还原呢?Git插件中并不像Svn插件直接提供有还原方式.其实无论是否提交至本地库或者远程库,还原操作的本质都是将文件的当前版本还原至之 ...

  4. Android RecyclerView And CardView

    Google I/O 2014大会公布Android L系统,还有Material Design全新的设计风格.而Material Design卡片式的设计.Google Play应用商店和G+ AP ...

  5. 利用jquery.fullPage.js 和 scrolloverflow.min.js 实现滚屏效果

    参考链接:https://blog.csdn.net/c11073138/article/details/79631036 /* 按着思路去search. */

  6. RGB颜色转换为多种颜色工具、公式

    http://www.easyrgb.com/index.php?X=CALC#Result http://www.easyrgb.com/index.php?X=MATH  

  7. 软件——机器学习与Python,输入输出的用法

    转自:http://www.cnblogs.com/graceting/p/3875438.html 输入很简单 x = input("Please input x:") Plea ...

  8. uvalive 6393(uva 1572) Self-Assembly 拓扑排序

    题意: 给出一些正方形,这些正方形的每一条边都有一个标号.这些标号有两种形式:1.一个大写字母+一个加减号(如:A+, B-, A-......), 2.两个0(如:00):这些正方形能够任意翻转和旋 ...

  9. 8.3 Android灯光系统_编写HAL_lights.c

    注意在led-classes.c中定义的led_class_attrs[]所建立的文件的属性应该改为0666,否则应用程序无权操作它 同时ledtrig-time.c里面对应新建的那几个delay_o ...

  10. PHP 分布式集群中session共享问题以及session有效期的设置

    https://blog.csdn.net/m_nanle_xiaobudiu/article/details/81177698