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. 一个测试基础面试题——如何测试web银行开户

    之前面试被问到过这样一个问题,自己答的都是一些UI界面上的case,看了一些大神的关于这类面试题的总结才知道自己差的不是一点半点,今天也总结下. 内管银行开户,有账号.用户名.用户证件类型.证件号三个 ...

  2. ansible-playbook 打通ssh无秘钥

    建议参考: http://www.cnblogs.com/jackchen001/p/6514018.html 这个代码清晰,效果佳! 参考链接: http://www.cnblogs.com/cao ...

  3. Sublime Text 相关教程(转)

    曾经有人说过,世界上有两种编辑器,好用和不好用的:而在好用的编辑器中,又分两种,免费的和死贵死贵的.譬如说VIM 和 TextMate,就是免费和死贵的典型.很不幸,今天的主角 Sublime Tex ...

  4. Failed to import pydot

    在使用keras进行模型绘制的时候,出现了一个错误 Failed to import pydot. You must install pydot and graphviz for `pydotprin ...

  5. AtCoder Grand Contest 014 E:Blue and Red Tree

    题目传送门:https://agc014.contest.atcoder.jp/tasks/agc014_e 题目翻译 有一棵有\(N\)个点的树,初始时每条边都是蓝色的,每次你可以选择一条由蓝色边构 ...

  6. bzoj 2179 FFT快速傅立叶 —— FFT

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2179 默写板子,注释的是忘记的地方. 代码如下: #include<iostream& ...

  7. ubuntu解决挂起后不能唤醒

    安装 laptop-mode 如果你不缺认自已是否安装了laptop-mode-tools工具包,可以在终端中输入下列命令来确认是否安装. dpkg -l | grep laptop-mode-too ...

  8. Mysql错误: ERROR 1205: Lock wait timeout exceeded; try restarting transaction

    MySQL:innodb的事务锁,一个线程占用着,简单做法是:执行mysql命令: show full processlist; 然后找出查询语句的系统id:kill掉被锁住的线程id:kill 12 ...

  9. Visual Studio Ultimate 2013 下载地址

    VS2013_RTM_ULT_CHS.iso 文件大小:2.87G 百度网盘下载地址: http://pan.baidu.com/s/1bn4gavX 微软官网下载地址: http://downloa ...

  10. 3-C++程序的结构1.1

    数据的共享和保护机制是C++的重要特性之一. 1.标识符的作用域与可见性 作用域讨论的是标识符的有效范围,可见性是讨论标识符是否可以被引用. a.作用域 作用域是一个标识符在程序正文中有效的区域.C+ ...