Codeforces Round #390 (Div. 2) A

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

31 2 -3

output

YES21 23 3

input

89 -12 3 4 -4 -10 7 3

output

YES21 23 8

input

10

output

NO

input

41 2 3 -5

output

YES41 12 23 34 4

题意:求区间和不是0有多少个解法:1 看样列貌似不是0就算区间本身,是0就右展开,不过这样代码就有点复杂(第二个)2 全为0的情况没有区间,数组和不为0,那么就算整个区间3 如果发现整个和为0,则考虑一个个加,发现和不为0就输出区间1-i,另外一个就算i+1~n
 1 #include<bits/stdc++.h>
 2 typedef long long LL;
 3 typedef unsigned long long ULL;
 4 using namespace std;
 5 const int maxn=1e5;
 6 int a[maxn];
 7 pair<int,int>Pa[maxn];
 8 int main(){
 9     int n;
10     int sum=0;
11     int flag=0;
12     cin>>n;
13     for(int i=1;i<=n;i++){
14        cin>>a[i];
15        sum+=a[i];
16     }
17     if(sum){
18         cout<<"YES"<<endl;
19         cout<<"1"<<endl;
20         cout<<"1"<<" "<<n<<endl;
21     }else{
22         sum=0;
23         for(int i=1;i<=n;i++){
24             sum+=a[i];
25             if(sum){
26                 cout<<"YES"<<endl;
27                 cout<<"2"<<endl;
28                 cout<<"1"<<" "<<i<<endl;
29                 cout<<i+1<<" "<<n<<endl;
30                 return 0;
31             }
32         }
33         cout<<"NO"<<endl;
34     }
35     return 0;
36 }
#include<bits/stdc++.h>

using namespace std;

int n, a[105], nule = 0, poc = 1;
vector <pair<int, int> > p;

int main(){
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        if (a[i] == 0) nule++;
    }
    if (nule == n){
        cout << "NO" << endl;
        return 0;
    }
    cout << "YES" << endl;
    for (int i = 1; i <= n; i++){
        if (a[i] != 0){
            while(i < n && a[i + 1] == 0) i++;
            p.push_back(make_pair(poc, i));
            poc = i + 1;
        }
    }
    if (poc != n + 1){
        p.push_back(make_pair(poc, n));
    }
    cout << p.size() << endl;
    for (int i = 0; i < p.size(); i++){
        pair <int, int> x = p[i];
        cout << x.first << ‘ ‘ << x.second << endl;
    }
    return 0;
}
时间: 2024-08-10 15:08:07

Codeforces Round #390 (Div. 2) A的相关文章

Codeforces Round #390 (Div. 2) 解题报告

时隔一个月重返coding…… 期末复习了一个月也不亏 倒是都过了…… 就是计组61有点亏 复变68也太低了 其他都还好…… 假期做的第一场cf 三道题 还可以…… 最后room第三 standing383简直人生巅峰…… 看楼上楼下都是两道题的 如果A题不错那么多估计能进前300了吧…… 这场倒是把之前两场的分加回来了 开头不错 这个假期争取紫名~ A.Lesha and array splitting 把给定的数组分割成几个区间 要求各个区间和不能为0 一开始没注意到分割之后的区间重新合成之

Codeforces Round #390 (Div. 2)

22:35-0:35  1.6.2017 A.Lesha and array splitting 题意:自己看 题解: 构造什么的最弱了 想了想,貌似除了0每个数单独一组就可以,只要有一个非0数则一定可以有解 0的话不停往前找到第一个非0然后合为一组 第一个数是0怎么办?先让第一个数往后找一个非0呗 比赛的时候智商骤减,写的代码好难看还写了好长时间,并且还WA一次...应该可以很简洁的吧 #include<iostream> #include<cstdio> #include<

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. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when

Codeforces Round #390 (Div. 2) D

All our characters have hobbies. The same is true for Fedor. He enjoys shopping in the neighboring supermarket. The goods in the supermarket have unique integer ids. Also, for every integer there is a product with id equal to this integer. Fedor has 

Codeforces Round #390 (Div. 2) A B C D

这是一场比较难的div2 ... 比赛的时候只出了AB A很有意思 给出n个数 要求随意的把相邻的数合并成任意多数 最后没有为0的数 输出合并区间个数与区间 可以想到0可以合到任何数上并不改变该数的性质 所以如果不全是0 最后一定是有答案的 把所有的0都合并到最近的非0数上去 非0数不变 #include<stdio.h> #include<string.h> #include<algorithm> #include<math.h> #include<

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿

Codeforces Round #424 (Div. 2) C. Jury Marks(乱搞)

题目链接:Codeforces Round #424 (Div. 2) C. Jury Marks 题意: 给你一个有n个数序列,现在让你确定一个x,使得x通过挨着加这个序列的每一个数能出现所有给出的k个数. 问合法的x有多少个.题目保证这k个数完全不同. 题解: 显然,要将这n个数求一下前缀和,并且排一下序,这样,能出现的数就可以表示为x+a,x+b,x+c了. 这里 x+a,x+b,x+c是递增的.这里我把这个序列叫做A序列 然后对于给出的k个数,我们也排一下序,这里我把它叫做B序列,如果我