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. BestCoder3 1001 Task schedule(hdu 4907) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4907 题目意思:给出工作表上的 n 个任务,第 i 个任务需要 ti 这么长的时间(持续时间是ti ~ ...

  2. iptables 端口映射

    一.环境和要实现功能 PC1的网络设置如下: eth0       192.168.0.29 内网 eth1 219.239.11.22 外网 PC2的网络设置则为:192.168.0.21 内网 我 ...

  3. Code:NFine目录

    ylbtech-Code:NFine目录 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部     6.返回顶部   作者:ylbtech出处:http://ylb ...

  4. 使用 NSData 分类实现,对 NSData 数据类型进行 AES 加密

    一般对NSData的数据类型进行加密,这里就将 .h .m 文件分享出来,有需要的可以直接粘贴使用.     下面是 .h 文件   #import <Foundation/Foundation ...

  5. IIS 部署 SSAS

    转自:http://blog.csdn.net/jinjazz/article/details/4058368 1.首先到分析服务器的SQLServer安装目录中找到如下目录和文件 2.然后为IIS建 ...

  6. Java中next() 与 nextLine() 区别

    next(): 1.一定要读取到有效字符后才可以结束输入. 2.对输入有效字符之前遇到的空白,next() 方法会自动将其去掉. 3.只有输入有效字符后才将其后面输入的空白作为分隔符或者结束符. 4. ...

  7. C - Present

    C - Present Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit ...

  8. 利用python数据分析panda学习笔记之Series

    1 Series a:类似一维数组的对象,每一个数据与之相关的数据标签组成 b:生成的左边为索引,不指定则默认从0开始. from pandas import Series,DataFrame imp ...

  9. 20个Flutter实例视频教程-第04节: 不规则底部工具栏制作-2

    视频地址: https://www.bilibili.com/video/av39709290/?p=4 博客地址: https://jspang.com/post/flutterDemo.html# ...

  10. 第一节:Java 语言基础

    5分30开始 18分正式开始议题 23分01开始创建项目: 讲个面向过程,函数式的方式 byte(8) char(16) short(16) int(32) long(64) long类型或者doub ...