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("%lld\n", x)
#define pi(x) printf("%d\n", 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;
  }
}