In this

**HackerEarth Raghu Vs Sayan problem solution**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 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).

## HackerEarth Raghu Vs Sayan problem solution.

`#include <cstdio>`

#include <vector>

#include <algorithm>

#include <cassert>

using namespace std;

#define MAXN 10000

#define MCAL 100000

#define MAXL 1000000000

vector<int> dish;

int main(){

int T, N, A, B, cal;

scanf("%d", &T);

assert(T>0 and T<=100);

while(T--){

dish.clear();

scanf("%d %d %d", &A, &B, &N);

assert(N>0 and N<=MAXN);

assert(A>0 and A<=MAXL);

assert(B>0 and B<=MAXL);

for(int i=0;i<N;i++){

scanf("%d", &cal);

assert(cal>0 and cal<=MCAL);

dish.push_back(cal);

}

sort(dish.begin(), dish.begin() + N);

int cntA = 0, cntB = 0;

for(int i=0;i<N;i++){

if(A>=dish[i]){

A-=dish[i];

cntA++;

}

if(B>=dish[i]){

B-=dish[i];

cntB++;

}

}

if(cntA>cntB){

printf("Raghu Won\n");

}else if(cntA<cntB)

printf("Sayan Won\n");

else

printf("Tie\n");

}

return 0;

}

## 0 Comments