Codeforces Round #775 (Div. 2, based on Moscow Open Olympiad in Informatics) 1649B - Game of Ball Passing Solution

  



Problem Link: https://codeforces.com/problemset/problem/1649/B

Solution in C++:

///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat  Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long n,t,i,s,mx;
    cin>>t;
    while(t--)
    {
        mx=0,s=0;
        cin>>n;
        long long  a[n+9];
        for(i=0; i<n; i++)
        {
            cin>>a[i];
            mx=max(mx,a[i]);
            s+=a[i];
        }
        if(mx==0&&s==0)
            cout<<"0"<<endl;
        else if(2*mx<=s)
            cout<<"1"<<endl;
        else
            cout<<2*mx-s<<endl;
    }
}

///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat  Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long n,t,i,s,mx;
    cin>>t;
    while(t--)
    {
        mx=0,s=0;
        cin>>n;
        long long  a[n+9];
        for(i=0; i<n; i++)
        {
            cin>>a[i];
            mx=max(mx,a[i]);
            s+=a[i];
        }
        if(mx==0&&s==0)
            cout<<"0"<<endl;
        else if(2*mx<=s)
            cout<<"1"<<endl;
        else
            cout<<2*mx-s<<endl;
    }
}


No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.