My solution is to sort the ranks, and then use binary search to determine the position. There is a better solution that sorts indexes instead, but I wanted something simpler to code for the contest. It's still O(n log n), so it should be accepted.

However, I got TLE, and I was able to fix it by just using lower_bound code I found at cplusplus.com (presumably, that's how it should be implemented in the standard library).

I was able to troubleshoot this quickly since I have faced this problem with OJ. Nevertheless, it entailed 600 seconds of penalty, plus some extra time to do the fix.

```
template <class FI, class T> FI my_lower_bound (FI first, FI last, const T& val)
{
auto count = distance(first,last);
while (count > 0)
{
auto it = first; auto step=count/2; advance (it,step);
if (*it<val) {
first=++it;
count-=step+1;
}
else count=step;
}
return first;
}
vector<string> findRelativeRanks(vector<int>& nums) {
vector<string> res;
vector<int> sorted(nums.begin(), nums.end());
sort(sorted.begin(), sorted.end());
for (auto n : nums) {
// TLE if replace with standard lower_bound
auto pos = nums.size() - distance(sorted.begin(), my_lower_bound(sorted.begin(), sorted.end(), n));
if (pos == 1) res.push_back("Gold Medal");
else if (pos == 2) res.push_back("Silver Medal");
else if (pos == 3) res.push_back("Bronze Medal");
else res.push_back(to_string(pos));
}
return res;
}
```