 # ERROR02-EDITORIAL

Practice

Author: Shubham_Goswami
Tester: Abhijeet Trigunait
Editorialist: Shubham Goswami

CAKEWALK

Array

# PROBLEM:

Chef asks Chefina for a date . But Chef is a hardworking guy and has a value for money so he already pre-planned about his date and fixed a budget to spend from his savings .

Given a fixed budget B and an array A[ ] of size N for the amount of N expenses .

You have to calculate the total amount and check whether the date costs him beyond his fixed budget . If the total amount goes beyond budget then print “YES” otherwise “NO” .

# EXPLANATION:

Given an array with n amounts of expenses and a fixed budget , so you have to check whether the total array sum goes beyond the fixed budget or not . If the total array sum goes beyond the budget you have to print “YES”, else print “NO” . If you don’t want to use array no issue , just keep on summing the amounts while taking input .

# SOLUTIONS:

Setter's Solution
``````/*

Author- Shubham Goswami

*/

#include<bits/stdc++.h>

#define lli long long int

using namespace std;

int main()

{

int T;    // This is for testcases (T)

cin>>T;

while(T--){  // T times the loop will take input N,B .

lli N,B,i,temp,sum=0;

cin>>N>>B;

for(i=0;i<N;i++){  // Taking  N inputs (the amounts, chef spent on date)

cin>>temp;

sum+=temp;     // calculating the total amount spent by chef

}

if(sum>B){      // Checking if the total amount spent(sum) goes beyond the budget(b)

cout<<"YES\n";

}

else{

cout<<"NO\n";

}

}

return 0;

}
``````