codeforces Round #618(Div.2)

Topic Link

Cf the first to write a title feel pretty good, he said the novice (novice) to participate in the Div2. And I wrote two questions is no then the. . . . . .
Because there are other tasks to complete, there is time to fix the latter problem, the first question I wrote Na Liangdao write it
to a topic link, I will not copy the title of the English side (Google translated for me English needs to be improved kinds of people is a good thing).
A question
Code:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int t,n,a[205];
int main()
{
    cin>>t;
    while(t--)
    {
        cin>>n;
        int sum=0;
        int f=0;
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        for(int i=0;i<n;i++)
        {
            if(a[i]==0)
            {
                a[i]+=1;
                sum++;
            }
            f+=a[i];
        }
        if(f==0)
        {
            for(int i=0;i<n;i++)
            {
                if(a[i]!=-1)
                {
                    a[i]+=1;
                    sum++;
                    break;
                }
            }
        }
        cout<<sum<<endl;
    }
    return 0;
}

B title

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#define maxn 200005
using namespace std;
int a[maxn];
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        for(int i=0;i<2*n;i++)
        {
            cin>>a[i];
        }
        sort(a,a+2*n);
        int k=a[n]-a[n-1];
        cout<<k<<endl;
    }
    return 0;
}

Published 81 original articles · won praise 3 · Views 2760

Guess you like

Origin blog.csdn.net/weixin_44641254/article/details/104250278