WUHAN - Editorial

PROBLEM LINK

Practice

PROBLEM STATEMENT

The city of Wuhan is afflicted by one of the deadliest viruses ever known to mankind. There are N centres in the city and every centre has A[i] people afflicted with the virus. The government has a total of M masks that needs to be given to the people afflicted by the virus. The government has appointed you to inform them whether these M marks will be enough for the afflicted people or they need to buy more.

So print 1 if the M masks will be enough or 0 if they need to buy more.

SOLUTION

You just need to calculate the sum of the patients in each centre and compare it with the total number of masks that the government has. Print 1 if masks are greater than or equal to the total number of patients , else print 0.

SOLUTION CODE

#include <bits/stdc++.h>
#define loop(i,n) for(i=0;i<n;i++)

using namespace std;
typedef long long int ll;

bool prime(ll s)
{
if (s <= 1)  return false;
if (s <= 3)  return true;
if (s%2 == 0 || s%3 == 0) return false;

for (ll i=5; i*i<=s; i=i+6)
    if (s%i == 0 || s%(i+2) == 0)
       return false;

return true;
}

int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int t=1;
cin>>t;
while(t--)
{
    ll ans = 0;
    
    ll n,m;
    cin>>n>>m;
    for(ll i=0;i<n;i++)
    {
        ll x;
        cin>>x;
        ans+=x;
    }
    if(m>=ans)
        cout<<1<<"\n";
    else
        cout<<0<<"\n";
}

return 0;
}