1436A - Reorder - CodeForces Solution


math *800

Please click on ads to support us..

Python Code:

t = int(input())
for _ in range(t):
    n,m = list(map(int,input().split()))
    a = list(map(int,input().split()))
    s = 0
    for i in a:
        s+=i 
    if s == m:
        print("YES")
    else:
        print("NO")

C++ Code:

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~**
*                       BISMILLAHIR RAHMANIR RAHIM                           *
**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define s(x)       sort(x.begin(),x.end())
#define all(a)     a.begin(),a.end()
#define rall(a)    a.rbegin(),a.rend()
#define rev(a)     reverse(all(a))
#define rv(x)      reverse(x.begin(),x.end())
#define g(v)       sort(v.begin(),v.end(),greater<int>())
#define rs(v)      sort(v.rbegin(),v.rend())
#define pf         printf
#define sf         scanf
#define pb         push_back
#define GCD(x,y)   __gcd(x, y)
#define ll         long long
#define lld        long double
#define sz(x)      x.size()
#define ff         first
#define sd         second
#define mp         make_pair
#define py         cout<<"YES"<<endl
#define pn         cout<<"NO"<<endl
#define ii         pair<ll,ll>
#define iii        pair<ii,int>
#define cii        pair<char, ii>
#define pq         map<char,vector<ll>>
#define CheckMate  return;
using namespace std;
const int N = 100001;

const ll MOD=1e9+7;

vector <ll> primeList;
vector<bool>visit(N);
void seive()
{
    ll num=N;
    for(int i=4; i<=num; i+=2) visit[i]=true;
    primeList.push_back(2);

    for(int i=3; i<=num; i+=2)
    {
        if(visit[i]==false)
        {
            primeList.push_back(i);
            if(sqrt(num)>=i)
            {
                for(int j=i+i; j<=num; j+=i) visit[j]=true;
            }
        }
    }
}

vector<ll> divisors(ll n)
{
    vector<ll> d;
    for(ll i=1; i*i<=n; i++)
    {
        if(n%i==0)
        {
            if(n/i!=i) d.pb(n/i);
            d.pb(i);

        }
    }
    return d;
}

vector<ll> primefactor(int num)
{
    vector <ll> primes;
    int x = num;
    for(int i=0; primeList[i]*primeList[i]<=num; i++)
    {

        while(num%primeList[i]==0)
        {
            num=num/primeList[i];
            primes.push_back(primeList[i]);
            if(num==1)break;
        }
    }
    if(num!=1) primes.push_back(num);
    // for(int i=0; i<primes.size()-1; i++) cout<<primes[i]<<'*';
    //cout<<primes[primes.size()-1]<<" = "<<x<<endl;
    s(primes);
    return primes;
}

vector<ll> primefact(ll n)
{
    vector<ll>pf;
    while(n%2==0)
    {
        pf.push_back(2);
        n/=2;
    }

    ll ans=sqrt(n);

    for(ll i=3; i<=ans; i+=2)
    {
        while(n%i==0)
        {
            pf.push_back(i);
            n/=i;
        }
    }
    if(n>2) pf.push_back(n);
    s(pf);
    return pf;
}


bool check(ll n)
{
    int a=0,b=0;
    while(n>0)
    {
        if(n%10==4) a++;
        else b++;
        n/=10;
    }
    if(a==b) return true;
    return false;
}


void precalc(ll n)
{
//    if(check(n)) v.pb(n);
    if(n<1e9)
    {
        precalc(n*10+4);
        precalc(n*10+7);
    }

}
ll bigmod(ll a,ll b,ll m)
{
    if(b==0) return 1%m;
    ll x=bigmod(a,b/2,m);
    x=(x*x)%m;
    if(b%2==1) x=(x*a)%m;
    return x;
}
ll calculation(vector<int>& v)
{
    ll n=sz(v),cnt=0,sum=0;
    for(int i=n-1; i>=0; i--)
    {
        if(v[i]==0) cnt++;
        else sum+=cnt;
    }
    return sum;
}


int f(int n)
{
    return (n*(n+1))/2;
}

//----------------- Lets START --------------------//



void oacm()
{
    int n,k;
    cin>>n>>k;
    int sum=0;
    for(int i=0; i<n; i++)
    {
        int a;
        cin>>a;
        sum+=a;
    }
    sum==k ? py:pn;
}


int main()
{
    fast
    seive();
    int t=1;
    cin>>t;
    while(t--)
    {
        oacm();
        //cout<<endl;
    }

}

//---------------- THE END -----------------//






Comments

Submit
0 Comments
More Questions

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
700. Search in a Binary Search Tree
590. N-ary Tree Postorder Traversal
589. N-ary Tree Preorder Traversal
1299. Replace Elements with Greatest Element on Right Side
1768. Merge Strings Alternately
561. Array Partition I
1374. Generate a String With Characters That Have Odd Counts
1822. Sign of the Product of an Array
1464. Maximum Product of Two Elements in an Array
1323. Maximum 69 Number
832. Flipping an Image