1201B - Zero Array - CodeForces Solution


greedy math *1500

Please click on ads to support us..

Python Code:

input()
a=list(map(int, input().split()))
s=sum(a)
if s%2 or max(a)>s//2:
    print("NO")
else:
    print("YES")

C++ Code:

//Jai Shree Ram
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>


using namespace std;
using namespace __gnu_pbds;

#define int long long int
#define pb push_back
#define vi vector<int>
#define endl "\n"
#define all(p) p.begin(), p.end()
#define rep(i,l,r) for(int i=l;i<r;i++)
#define pin pair<int,int>
#define vpin vector<pin>
#define yes() cout<<"YES"<<endl
#define no() cout<<"NO"<<endl
const int N = 1e9+7;
const int M = 1e6+1;
int is_prime[M];
void sieve()
{
  int maxN=1e6;
  for(int i=1;i<=maxN;i++) is_prime[i]=1;
  is_prime[0]=is_prime[1]=0;
  
  for(int i=2;i*i<=maxN;i++)
  {
    if(is_prime[i])
    {
      for(int j=i*i;j<=maxN;j+=i)
      is_prime[j]=0;
    }
  }
}

int power(int x,int n)
{
    int var = 1;
    while(n>0)
    {
        if(n&1)
        {
            var = var*x;
            n--;
        }
        else
        {
            x*=x;
            n/=2;
        }
        
    }
    return var;
    
}

int binary_search(vector<int>&v,int n,int x)
{
    int low = 0;
    int high = n-1;
    int mid;
    while(high-low>1)
    {
        mid = (low+high)/2;
        if(x==v[mid])
        return -1;
        else if(x>v[mid])
        {
            low = mid + 1;
        }
        else if(x<v[mid])
        {
            high = mid-1;
        }
    }
    if(x==v[high]||x==v[low])
    return -1;
    else
    {
        if(x>v[high])
        return high+1;
        else if(x<v[low])
        return low;
        else 
        return low+1;
    }
}


int powermod(int a, int b, int m)
{
    if (b == 0) return 1;
    int k = powermod(a, b / 2, m);
    k = k * k;
    k %= m;
    if (b & 1) k = (k * a) % m ;
    return k;
}
 
int inverse(int a, int mod) {
    return powermod(a, mod - 2, mod);
}

int kadane(vector<int>&v,int n)
{
  int current =0,maximum=0;
  for(int i=0;i<n;i++)
  {
    current+=v[i];
    if(current<0)
    current=0;
    maximum = max(maximum,current);
  }
  return maximum;
}



int32_t main() {
	// your code goes here
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	vi a(n);
	rep(i,0,n)
	cin>>a[i];
	sort(all(a));
	int sum=0;
	rep(i,0,n)
	sum+=a[i];
	if(sum%2==0&&a[n-1]<=sum-a[n-1])
	yes();
	else
	no();
	return 0;
}




Comments

Submit
0 Comments
More Questions

229. Majority Element II
222. Count Complete Tree Nodes
215. Kth Largest Element in an Array
198. House Robber
153. Find Minimum in Rotated Sorted Array
150. Evaluate Reverse Polish Notation
144. Binary Tree Preorder Traversal
137. Single Number II
130. Surrounded Regions
129. Sum Root to Leaf Numbers
120. Triangle
102. Binary Tree Level Order Traversal
96. Unique Binary Search Trees
75. Sort Colors
74. Search a 2D Matrix
71. Simplify Path
62. Unique Paths
50. Pow(x, n)
43. Multiply Strings
34. Find First and Last Position of Element in Sorted Array
33. Search in Rotated Sorted Array
17. Letter Combinations of a Phone Number
5. Longest Palindromic Substring
3. Longest Substring Without Repeating Characters
1312. Minimum Insertion Steps to Make a String Palindrome
1092. Shortest Common Supersequence
1044. Longest Duplicate Substring
1032. Stream of Characters
987. Vertical Order Traversal of a Binary Tree
952. Largest Component Size by Common Factor