Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

HackerEarth Raghu Vs Sayan problem solution

YASH PAL, 31 July 202415 February 2026
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

 

 

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 Wonn");
}else if(cntA<cntB)
printf("Sayan Wonn");
else
printf("Tien");
}
return 0;
}
 
coding problems solutions HackerEarth HackerEarth

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes