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:

  • 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 题意:求区间和不是0有多少个
解法:
1 看样列貌似不是0就算区间本身,是0就右展开,不过这样代码就有点复杂(第二个)
2 全为0的情况没有区间,数组和不为0,那么就算整个区间
3 如果发现整个和为0,则考虑一个个加,发现和不为0就输出区间1-i,另外一个就算i+1~n
 #include<bits/stdc++.h>
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;
const int maxn=1e5;
int a[maxn];
pair<int,int>Pa[maxn];
int main(){
int n;
int sum=;
int flag=;
cin>>n;
for(int i=;i<=n;i++){
cin>>a[i];
sum+=a[i];
}
if(sum){
cout<<"YES"<<endl;
cout<<""<<endl;
cout<<""<<" "<<n<<endl;
}else{
sum=;
for(int i=;i<=n;i++){
sum+=a[i];
if(sum){
cout<<"YES"<<endl;
cout<<""<<endl;
cout<<""<<" "<<i<<endl;
cout<<i+<<" "<<n<<endl;
return ;
}
}
cout<<"NO"<<endl;
}
return ;
}
#include<bits/stdc++.h>

using namespace std;

int n, a[], nule = , poc = ;
vector <pair<int, int> > p; int main(){
cin >> n;
for (int i = ; i <= n; i++){
cin >> a[i];
if (a[i] == ) nule++;
}
if (nule == n){
cout << "NO" << endl;
return ;
}
cout << "YES" << endl;
for (int i = ; i <= n; i++){
if (a[i] != ){
while(i < n && a[i + ] == ) i++;
p.push_back(make_pair(poc, i));
poc = i + ;
}
}
if (poc != n + ){
p.push_back(make_pair(poc, n));
}
cout << p.size() << endl;
for (int i = ; i < p.size(); i++){
pair <int, int> x = p[i];
cout << x.first << ' ' << x.second << endl;
}
return ;
}

Codeforces Round #390 (Div. 2) A的更多相关文章

  1. Codeforces Round #390 (Div. 2) D. Fedor and coupons(区间最大交集+优先队列)

    http://codeforces.com/contest/754/problem/D 题意: 给定几组区间,找k组区间,使得它们的公共交集最大. 思路: 在k组区间中,它们的公共交集=k组区间中右端 ...

  2. Codeforces Round #390 (Div. 2) C. Vladik and chat(dp)

    http://codeforces.com/contest/754/problem/C C. Vladik and chat time limit per test 2 seconds memory ...

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

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

  4. Codeforces Round #390 (Div. 2)

    时隔一个月重返coding…… 期末复习了一个月也不亏 倒是都过了…… 就是计组61有点亏 复变68也太低了 其他都还好…… 假期做的第一场cf 三道题 还可以…… 最后room第三 standing ...

  5. Codeforces Round #390 (Div. 2) E(bitset优化)

    题意就是一个给出2个字符矩阵,然后进行匹配,输出每个位置的匹配的结果 (超出的部分循环处理) 一种做法是使用fft,比较难写,所以没有写 这里使用一个暴力的做法,考虑到一共只出现26个字符 所以使用一 ...

  6. Codeforces Round #390 (Div. 2) A B C D

    这是一场比较难的div2 ... 比赛的时候只出了AB A很有意思 给出n个数 要求随意的把相邻的数合并成任意多数 最后没有为0的数 输出合并区间个数与区间 可以想到0可以合到任何数上并不改变该数的性 ...

  7. Codeforces Round #390 (Div. 2) D

    All our characters have hobbies. The same is true for Fedor. He enjoys shopping in the neighboring s ...

  8. Codeforces Round #390 (Div. 2) B

    Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. ...

  9. Codeforces Round #390 (Div. 2) A+B+D!

    A. Lesha and array splitting 水题模拟.(0:10) 题意:给你一个n个元素的数组,求能否把这个数组分成若干连续小段,使得每段的和不为0.如有多种解输出任意一个. 思路:搞 ...

随机推荐

  1. ffmpeg xcode 中的使用

    最近比较闲,苦于ios设备上没有直接播放torrent 文件的软件,开始折腾了.找了不少资料有了思路.但是其中用到了ffmpeg 这个东西. ffmpeg 是通用的一个视频解决框架,用C语言编写,通用 ...

  2. zabbix 用户自定义监控参数添加

    1. item  key的添加 key可以带参数,该参数为一个数组列表,可以同时传递多个参数,key的格式如下 key -- [ parameters] -- 例如: vfs.fs.size[/] v ...

  3. PHP生成一个不重复随机数组的封装方法

    <?php /** array unique_rand( int $min, int $max, int $num )* 生成一定数量的不重复随机数* $min 和 $max: 指定随机数的范围 ...

  4. Java网络编程InetAddress类

    InetAddress用来代表IP地址.一个InetAdress的对象就代表着一个IP地址, getByName(String host):在给定主机名的情况下确定主机的 IP 地址,主机名可以是机器 ...

  5. Keras 可视化 model

    参考:https://keras.io/visualization/ error解决参考:http://blog.csdn.net/wangjian1204/article/details/50346 ...

  6. BZOJ2006:超级钢琴(ST表+堆求前K大区间和)

    Description 小Z是一个小有名气的钢琴家,最近C博士送给了小Z一架超级钢琴,小Z希望能够用这架钢琴创作出世界上最美妙的音乐. 这架超级钢琴可以弹奏出n个音符,编号为1至n.第i个音符的美妙度 ...

  7. why ftp服务器采用多进程模式

    为什么没有采用多线程或者IO复用,原因是在多线程或IO复用的情况下,当前目录是共享的,无法根据每一个连接来拥有自己的当前目录. 多进程模式下,一个连接拥有2个进程,一个是nobody进程,一个是服务进 ...

  8. dubbo 自定义过滤器,打印接口调用信息

    dubbo提供了web filter类似的com.alibaba.dubbo.rpc.Filter,这样,我们可以在dubbo提供的服务提供方和消费方都可以自定义过滤 器,从而可以获得方法调用的时间或 ...

  9. Java--23种设计模式之decorator模式

    装饰模式:装饰模式以对客户端透明的方式扩展对象的功能,是继承关系的一个替代方案,提供比继承更多的灵活性.动态给一个对象增加功能,这些功能可以再动态的撤消.增加由一些基本功能的排列组合而产生的非常大量的 ...

  10. 后端开发-Mybatis开发之一

    2018-12-29 Mybatis简单开发:我是在eclipse上进行Java项目开发 目录结构如下:      内容如下: mysql.sql: 用于创建测试用的数据库以及表: 可以直接导入mys ...