Codeforces Round #390 (Div. 2)A
2017-01-07 10:55
447 查看
A. Lesha and array splitting
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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
#include <bits/stdc++.h> using namespace std; int main(){ int n; int a[105]; scanf("%d",&n); int sum=0; int h=0; for(int i=0;i<n;i++){ scanf("%d",a+i); sum+=a[i]; if(a[i]==0){ h++; } } if(sum!=0){ puts("YES"); puts("1"); printf("%d %d\n",1,n); } else if(h==n){ puts("NO"); } else{ int k=0; int l; for(int i=0;i<n;i++){ k+=a[i]; if(k!=0){ l=i; break; } } puts("YES"); puts("2"); printf("%d %d\n",1,l+1); printf("%d %d\n",l+2,n); } return 0; }
相关文章推荐
- 浅谈熵和打升级 (A brief talk about entropy and Sheng ji)
- ubuntu下apache2-php-mysql的环境配置
- 【LeetCode】 392. Is Subsequence
- YihAN_Z's 测试之——小熊的烦恼
- Yii框架弹出框功能示例
- java 使用JNDI数据源
- MySQL server version for the right syntax to use near '-1.stu stu0_' at line 1
- 做计算机图形学研究需要哪些基本技能?
- Js的核心知识点
- qduoj 数组中出现最多的元素
- python学习-3.一些常用模块用法
- python学习-3.一些常用模块用法
- Weblogic集群
- 好的sql
- ORACLE列转行示例
- 【ES6】Generators的原理
- android_图片转视频_image2video
- Eclipse使用技巧
- 【Python语法】Python中的三种装饰器语法
- 【原】Android热更新开源项目Tinker源码解析系列之三:so热更新