1230A - Dawid and Bags of Candies - CodeForces Solution


brute force implementation *800

Please click on ads to support us..

Python Code:

from audioop import reverse
from cmath import *
from dataclasses import dataclass
from math import *
from decimal import *
from collections import *
from re import A
import sys
def _input(): return map(int, input().split())
def _list(): return list(map(int, input().split()))
def _int(): return int(input())



def solves():
    a,b,c,d=_input()
    if (a+b+c+d)%2!=0:
        print("NO")
    else:
        if a+b==c+d or a+c==b+d or a+d==c+b or a+b+c==d or a+b+d==c or a+c+d==b or a+b+c+d==0 or b+c+d==a:
            print("YES")
        else:
            print("NO")
    
t=1
for _ in range(0,t):
    solves()

C++ Code:

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define ll long long
using namespace std;

void QuickSilver(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
ll gcd(ll a, ll b) { return ((b == 0) ? a : gcd(b, a % b));}
ll lcm(ll a, ll b) { return (b / gcd(a, b)) * a;}
bool sortysort(pair<ll, ll>& a,pair<ll, ll>& b)
{ if(a.second!=b.second)
        return a.second < b.second;
    else
        return a.first>b.first;
}
string PrintNum(long long n,string s){

    if(n==1) {
        s+= (n & 1);
        return s;}
    PrintNum(n>>1,s);
   s+=(n&1); }

int main() {
    QuickSilver();
vector<ll>v(4);
for(auto&it:v)cin>>it;
    for(int i=0;i<(1<<4);i++){
        ll sum=0,sum2=0;
        for(int j=0;j<4;j++){
            if((i>>j)&1){
               sum+=v[j];
            }
            else sum2+=v[j];
        }
        if(sum==sum2)return cout<<"YES",0;
    }
    cout<<"NO";
        return 0;
}
  		  	     	 	  		     	 				


Comments

Submit
0 Comments
More Questions

Bricks Game
Char Sum
Two Strings
Anagrams
Prime Number
Lexical Sorting Reloaded
1514A - Perfectly Imperfect Array
580A- Kefa and First Steps
1472B- Fair Division
996A - Hit the Lottery
MSNSADM1 Football
MATCHES Playing with Matches
HRDSEQ Hard Sequence
DRCHEF Doctor Chef
559. Maximum Depth of N-ary Tree
821. Shortest Distance to a Character
1441. Build an Array With Stack Operations
1356. Sort Integers by The Number of 1 Bits
922. Sort Array By Parity II
344. Reverse String
1047. Remove All Adjacent Duplicates In String
977. Squares of a Sorted Array
852. Peak Index in a Mountain Array
461. Hamming Distance
1748. Sum of Unique Elements
897. Increasing Order Search Tree
905. Sort Array By Parity
1351. Count Negative Numbers in a Sorted Matrix
617. Merge Two Binary Trees
1450. Number of Students Doing Homework at a Given Time