C++ code to find out if everyone will get ice cream

C++Server Side ProgrammingProgramming

Suppose, there are three groups of people coming to a party. The first group of people likes butterscotch ice cream and do not like any other flavors of ice cream, the second group of people only dislikes strawberry ice cream and like every other flavor, and the third group likes all kinds of ice cream. Now, there are x people of the first group, y people of the second group, and z people of the third group are coming to a party, and everyone should have at least one icecream of their liking. The party organizers have brought a packs of butterscotch ice cream, b packs of chocolate ice cream, and c packs of strawberry ice cream. We have to find out if all the people at the party will be able to get one piece of their favorite ice cream or not.

So, if the input is like a = 6, b = 5, c = 5, x = 3, y = 8, z = 4, then the output will be Possible.


To solve this, we will follow these steps −

if a < x or a + b < x + y or a + b + c < x + y + z, then:
   print("Not Possible.")


Let us see the following implementation to get better understanding −

#include <bits/stdc++.h>
using namespace std;
#define N 100
void solve(int a, int b, int c, int x, int y, int z) {
   if (a < x || a + b < x + y || a + b + c < x + y + z)
      cout<<"Not Possible.";
int main() {
   int a = 6, b = 5, c = 5, x = 3, y = 8, z = 4;
   solve(a, b, c, x, y, z);
   return 0;


6, 5, 5, 3, 8, 4


Updated on 29-Mar-2022 08:39:44