Raghu Vs Sayan

Raghu and Sayan both like to eat (a lot) but since they are also looking after their health, they can only eat a limited amount of calories per day. So when Kuldeep invites them to a party, both Raghu and Sayan decide to play a game. The game is simple, both Raghu and Sayan will eat the dishes served at the party till they are full, and the one who eats the maximum number of distinct dishes is the winner. However, both of them can only eat a dishes if they can finish it completely i.e. if Raghu can eat only 50 kCal in a day and has already eaten dishes worth 40 kCal, then he can't eat a dish with calorie value greater than 10 kCal.

Given that all the dishes served at the party are infinite in number, (Kuldeep doesn't want any of his friends to miss on any dish) represented by their calorie value(in kCal) and the amount of kCal Raghu and Sayan can eat in a day, your job is to find out who'll win, in case of a tie print “Tie” (quotes for clarity).

Example:

Input:  a = 10, b = 20, n = 3, arr = [10,5,4]
Output: Sayan Won

Approach

C++

#include <bits/stdc++.h>
using namespace std;

void raghuAndSayan(int aint bint nint arr[])
{

    sort(arrarr + n);
    int i = 0;
    while (i < n && a > 0)
    {
        a = a - arr[i];
        if (a >= 0)
            i++;
    }
    int j = 0;
    while (j < n && b > 0)
    {
        b = b - arr[j];
        if (b >= 0)
            j++;
    }
    if (i == j)
        cout << "Tie\n";
    else if (i > j)
        cout << "Raghu Won\n";
    else
        cout << "Sayan Won\n";
}
int main()
{
    int a = 10b = 20n = 3;

    int arr[n] = {1054};

    raghuAndSayan(abnarr);

    return 0;
}


No comments:

Post a Comment