A. Lesha and array splitting

time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard 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;则不可能了; 贪心吧。
下面给出AC代码:
 #include<iostream>
using namespace std;
int n,a[],i,s,b;
int main()
{
cin>>n;
for(i=;i<=n;i++)
{
cin>>a[i];
s+=a[i];
if(a[i])
b=i;
}
if(b==)
cout<<"NO\n";
else if(s)
cout<<"YES\n1\n"<<<<" "<<n<<"\n";
else
cout<<"YES\n2\n"<<<<" "<<b-<<"\n"<<b<<" "<<n<<"\n";
return ;
}


Codeforces 754A Lesha and array splitting(简单贪心)的更多相关文章

  1. 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 ...

  2. 【codeforces 754A】Lesha and array splitting

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

  3. Codeforces Round #390 (Div. 2) A. Lesha and array splitting

    http://codeforces.com/contest/754/problem/A 题意: 给出一串序列,现在要把这串序列分成多个序列,使得每一个序列的sum都不为0. 思路: 先统计一下不为0的 ...

  4. CodeForces - 794C:Naming Company(博弈&简单贪心)

    Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little thi ...

  5. Codeforces 845C. Two TVs 思路:简单贪心算法

    题目: 题目原文链接:http://codeforces.com/contest/845/problem/C 题意:现在我们有一个电视清单,有两个电视,电视清单上有每一个节目的开始时间和结束时间. 电 ...

  6. codeforces 402 D. Upgrading Array(数论+贪心)

    题目链接:http://codeforces.com/contest/402/problem/D 题意:给出一个a串和素数串b .f(1) = 0; p为s的最小素因子如果p不属于b , 否则 . a ...

  7. Codeforces F. Maxim and Array(构造贪心)

    题目描述: Maxim and Array time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  8. cf754 A. Lesha and array splitting

    应该是做麻烦了,一开始还没A(幸好上一次比赛水惨了) #include<bits/stdc++.h> #define lowbit(x) x&(-x) #define LL lon ...

  9. Educational Codeforces Round 69 (Rated for Div. 2) C. Array Splitting 水题

    C. Array Splitting You are given a sorted array

随机推荐

  1. iOS----------如何检查域名是否支持ipv6

    http://ipv6-test.com/validate.php  这个地址  也可以检测到! 1.检查你所用到的库,像af 3.0以上什么的(不用改),其他的库自己去搜下是否支持ipv6吧. 2. ...

  2. 重温javascript数据类型

    在javaScript中,有五种简单的数据类型,分别是 Undefined Null Boolean Number String 还有一种复杂的数据类型object,object本质是有一组无序的名值 ...

  3. 在html中使用js

    1.使用defer属性可以让脚本在文档完全呈现出来之后在执行,延迟脚本总是按照制定他们的顺序进行. 2.使用async属性可以表示当前脚本不必等待其他脚本,也不必阻塞文档呈现,不能保证异步顺序按照它们 ...

  4. su 和 sudo 命令的区别-转载

    link 一. 使用 su 命令临时切换用户身份                   1.su 的适用条件和威力   su命令就是切换用户的工具,怎么理解呢?比如我们以普通用户beinan登录的,但要 ...

  5. java 快速排序

    快速排序比插入排序快了两个数量级 package test.sort; public class Paixu { public static void main(String[] args) { // ...

  6. js把通过图片路径生成base64

    主要思想: 使用canvas.toDataURL()方法将图片的绝对路径转换为base64编码. 一.图片在本地服务器: var imgSrc = "img/1.jpg";//本地 ...

  7. a标签实现一键拨号、发短信、发邮件、发起QQ会话

    a标签href的妙用:   <a href="tel:400-888-6633">拨打电话<a> <a href="sms:19956321 ...

  8. ES6(二) Destructuring-变量的解构赋值

    1.解构的含义 允许按照一定的模式,从数组和对象中取值,对变量进行赋值,称为解构. 解构赋值时,只要等号右边的值不是对象,就先将其转换成对象. 本质上,这种写法属于 “模式匹配”,只要两边模式相同,左 ...

  9. python实现二分查找算法

    二分查找算法也成为折半算法,对数搜索算法,一会中在有序数组中查找特定一个元素的搜索算法.搜索过程是从数组中间元素开始的 如果中间元素正好是要查找的元素,则搜索过程结束:如果查找的数大于中间数,则在数组 ...

  10. 如何把Excel中的单元格等对象保存成图片

    对于Excel中的很多对象,比如单元格(Cell),图形(shape),图表(chart)等等,有时需要将它们保存成一张图片.就像截图一样. 最近做一个Excel相关的项目,项目中遇到一个很变态的需求 ...