EN123-Editorial

PROBLEM LINK:

Practice
Contest

Author: Sandeep Singh
Tester: Arkaprabha Ghosh
Editorialist: Sandeep Singh

DIFFICULTY:

CAKEWALK

PREREQUISITES:

None

PROBLEM:

Given the price of all dishes, check if Debanjan can pay the bill or not

EXPLANATION:

This is a very simple problem requiring no complex thinking. Just add all the prices and store them in a variable say tb. The balance available is K. If tb is greater than K, then he cannot pay the bill, else he can. Note that the output is case sensitive. Printing “Yes”,“yes” etc will result in WA verdict.

SOLUTIONS:

Setter's Solution
#include <bits/stdc++.h>
#define ll long long int
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define scanarr(a,b,c) for(int i=b;i<c;i++)cin>>a[i]
#define showarr(a,b,c) for(int i=b;i<c;i++)cout<<a[i]<<' '
#define ln cout<<'\n'
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mod 1000000007
#define MAX 100005
using namespace std;
////////////////////////////////////////////////////////////////CODE STARTS HERE////////////////////////////////////////////////////////////////
void solve(){
    int n,k,i,tmp;
    cin>>n>>k;
    int tb=0;
    for(i=1;i<=n;i++){
        cin>>tmp;
        tb+=tmp;
    }
    cout<<(tb>k?"NO":"YES")<<endl;
    
    
}
int main(){
   
    int t;
    cin>>t;
    while(t--)
        solve();
} 
Tester's Solution
for _ in range(int(input())):
    n, k = map(int, input().split())
    sum = 0
    l = list(map(int, input().split()))
    for i in range(n):
        sum += l[i]
    if(sum <= k):
        print("YES")
    else:
        print("NO")