Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone

HackerEarth Leaderboard Standings problem solution

YASH PAL, 31 July 2024
In this HackerEarth Leaderboard Standings problem solution, There were N submissions made in a programming contest containing infinite problems. Each submission earned the contestant 100 points as none of the submissions is wrong or a partial submission. You are given the details of the submissions – the username of the contestant and the time taken to solve the problem. Your task is to print the rank list according to the following rules:
The contestant with a higher score gets a higher rank.
If the scores are tied, then the contestant with the least sum of the time taken to solve the problems gets a higher rank.
In case of a tie in both scores and the sum of the time taken, they are ranked lexicographically according to their usernames.
HackerEarth Leaderboard Standings problem solution

HackerEarth Leaderboard Standings problem solution.

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define si(x) scanf("%d", &x)
#define sc(x) scanf("%c", &x)
#define sl(x) scanf("%lld", &x)
#define pl(x) printf("%lldn", x)
#define pi(x) printf("%dn", x)
#define gu getchar_unlocked
#define pu putchar_unlocked
#define setbits __builtin_popcountll
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define speed ios::sync_with_stdio(false)

struct newtype{
int score;
int time;
string name;
};
typedef struct newtype node;

vector <node> v;
map < string, pair<int, int> > m;

bool cmp(node A, node B){
if(A.score != B.score){
return A.score > B.score;
}
else if(A.time != B.time){
return A.time < B.time;
}
else{
return A.name < B.name;
}
}

int main(){
int n, i;
si(n);
for(i = 0; i < n; i++){
string s; int t;
cin>>s; si(t);
auto it = m.find(s);
if(it != m.end()){
pair<int, int> P = it -> second;
P.first += 100;
P.second += t;
m[s] = P;
}
else{
m[s] = mp(100, t);
}
}
for(auto it = m.begin(); it != m.end(); it++){
node N;
N.name = it -> first;
N.score = (it -> second).first;
N.time = (it -> second).second;
v.pb(N);
}
sort(v.begin(), v.end(), cmp);
for(i = 0; i < v.size(); i++){
cout<<i + 1<<" "<<v[i].name<<endl;
}
}
coding problems solutions

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes