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 ;
}

最新文章

  1. centos 6 cglib
  2. 使用ionic framework创建一个简单的APP
  3. Mac下命令行中用sublime打开指定文件 设置方法
  4. android 学习随笔十四(页面跳转与数据传递)
  5. Java DES 加解密文件
  6. jQuery选择器总结 转
  7. 版本控制-cvs
  8. poj 1066 Treasure Hunt
  9. [c#]asp.net开发微信公众平台(1)数据库设计
  10. cocos2d-x游戏开发系列教程-搭建cocos2d-x的windows开发环境
  11. Wamp环境下配置--Apache虚拟主机
  12. Oracle笔试题库之问答题篇-总共60道
  13. 229. Majority Element II求众数II
  14. LeetCode算法题-Factorial Trailing Zeroes(Java实现)
  15. PHP 依赖注入,依赖反转 (IOC-DI)
  16. 小程序和H5互调
  17. jquery 中多选和全选
  18. 继续JS之DOM对象二
  19. 目标检测(一)RCNN--Rich feature hierarchies for accurate object detection and semantic segmentation(v5)
  20. 【react】---context的基本使用新版---【巷子】

热门文章

  1. ES6 新特性之Symbol
  2. SVG-Android开源库——SVG生成Vector资源文件的编辑预览工具
  3. BestCoder3 1002 BestCoder Sequence(hdu 4908) 解题报告
  4. smarty模板引擎基础(二)
  5. Opencv— — Bias and Gain
  6. Kvm学习文档记录
  7. exBSGS算法
  8. 二维码扫描极速版2.0.apk
  9. 【219】◀▶ IDL 数学函数说明
  10. codevs-1204