Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Codechef Scores API
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n; cin>>n;
std::vector<pair <int, pair<string, int>>> apiData;
for(int i = 0; i < n;i++)
{
int timeStamp, scoreObtained;
string userName;
cin>>timeStamp>>userName>>scoreObtained;
apiData.push_back({timeStamp, {userName, scoreObtained}});
}
sort(apiData.begin(), apiData.end());
map<string, int> sortedUsersWithScores, sortedUsersWithMaximumScores;
for(int i = 0; i < n;i++)
sortedUsersWithScores[apiData[i].second.first]+=apiData[i].second.second;
int maxScore=INT_MIN;
for(int i = 0; i < n;i++)
maxScore = max(maxScore, sortedUsersWithScores[apiData[i].second.first]);
for(int i = 0; i < n;i++)
{
if(maxScore == sortedUsersWithScores[apiData[i].second.first])
{
sortedUsersWithMaximumScores[apiData[i].second.first] += apiData[i].second.second;
if(sortedUsersWithMaximumScores[apiData[i].second.first] >= maxScore)
{
cout<<apiData[i].second.first<<endl;
break;
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment