Computer Science, asked by swethachowdary845, 11 months ago

Serena narrated an interesting game to her friends. The game goes like this. Initially, there is a table with an empty cup and n water mugs on it. Then all the players take turns to move. During a move, a player takes a non-empty mug of water and pours all the water from it into the cup. If the cup overfills, then we assume that this player has lost the game. As soon as Serena's friends heard of the game, they wanted to play it. Serena, on the other hand, wanted to find out whether her friends can play the game in such a way that there are no losers. You are given the volumes of all the mugs and the cup. Also, you know that Serena has (n - 1) friends. Determine if Serena's friends can play the game so that nobody loses. FUNCTIONAL REQUIREMENTS: int printresult(int*,int,int);

Answers

Answered by jobastin
9

Answer:

#include<iostream>

#include <bits/stdc++.h>  

using namespace std;

int main()

{

int n,c;

std::cin>>n>>c;

int mugs[n];

for(int i=0;i<n;i++)

{

std::cin>>mugs[i];

}

sort(mugs,mugs+n,greater<int>());

int t=0;

for(int i=0;i<n-1;i++)

{

t=t+mugs[i];

 if(mugs[i]<=c && t<=c)

 {

   continue;

 }

 else

 {

   std::cout<<"NO";

   break;

 }

}

std::cout<<"YES";

}

Explanation:

Answered by parthik1999
30

Answer:

#include<iostream>

using namespace std;

int main()

{

 int n,c,i,sum=0;

 std::cin>>n;

 std::cin>>c;

 int arr[n];

 for(i=0;i<n;i++)

 {

   std::cin>>arr[i];

 }

 for(i=0;i<n;i++)

 {

   sum=sum+arr[i];

 }

 if(sum<=c)

 {

   std::cout<<"YES";

 }

 else

 {

   std::cout<<"NO";

 }

}

Explanation:

Similar questions