Created
July 4, 2021 21:09
-
-
Save MrTwinkleSharma/9126d7891dbdec07f8a7996527231606 to your computer and use it in GitHub Desktop.
Codechef Scores API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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