Codeforces Round #390 (Div. 2)A
来源:互联网 发布:asp网络程序怎么样? 编辑:程序博客网 时间:2024/05/16 14:48
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
#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;}
- Codeforces Round #390 (Div. 2)A
- Codeforces Round #390 (Div. 2)(A+B)
- Codeforces Round #390 (Div. 2) A+B+D!
- A. Lesha and array splitting Codeforces Round #390 (Div. 2)
- Codeforces Round #390 (Div. 2)A Lesha and array splitting
- Codeforces Round #131 (Div. 2) A B
- Codeforces Round #174 (Div. 2) Problem A
- Codeforces Round #173 (Div. 2) A.Bit++
- Codeforces Round #181 (Div. 2) A题
- Codeforces Round #184 (Div. 2) A题
- Codeforces Round #185 (Div. 2)--A,B
- Codeforces Round #172 (Div. 2) A题
- Codeforces Round #166 (Div. 2) A题
- Codeforces Round #132 (Div. 2) A题
- Codeforces Round #131 (Div. 2) A题
- Codeforces Round #133 (Div. 2) A题
- Codeforces Round #137 (Div. 2) A题
- Codeforces Round #138 (Div. 2) A题
- Codeforces Round #390 (Div. 2)B
- 浅谈熵和打升级 (A brief talk about entropy and Sheng ji)
- VirtualBox扩容失败-Progress state: VBOX_E_NOT_SUPPORTED
- UpdatePanel控件的使用
- 每一段记忆都值得被珍藏---致敬研一生活
- Codeforces Round #390 (Div. 2)A
- svn安装+配置客户端方法2【申明:来源于网络】
- Spring Boot 快速入门
- OpenCV进阶之路:一个简化的视频摘要程序
- 线程及消息
- Android开发 com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-.
- cmd/bat如何自动请求管理员权限而不需要右键管理员运行
- 自定义控件 随着手滑动DrawView
- Mybatis Generator 生成的mapper只有insert方法