[C++] Why time limit on sort method during contest, and got accepted on re-submission?
No need for explanation, straightforward solution.\n71 / 71 test cases passed, but took too long. Resubmission of same code got accepted.\nWhy it happened? Is i
No need for explanation, straightforward solution.\n71 / 71 test cases passed, but took too long. Resubmission of same code got accepted.\nWhy it happened? Is it normal or there is something wrong in my code.\n\n```\nbool comp(const pair<int,int> &a, const pair<int,int> &b)\n{\n    if(a.first==b.first) return a.second>b.second;\n    return a.first>b.first;\n}\n\nclass Solution {\npublic:\n    vector<int> getStrongest(vector<int>& arr, int k) {\n        int n=arr.size();\n        sort(arr.begin(),arr.end());\n        \n        int med=arr[(n-1)/2];\n        vector< pair<int,int> > ans;\n        for(int i=0;i<n;i++)  ans.push_back({ abs(arr[i]-med),arr[i] });\n        \n        sort(ans.begin(),ans.end(),comp);\n        vector<int> rv;\n        for(int i=0;i<k;i++)   rv.push_back(ans[i].second);\n        return rv;\n    }\n};
['C', 'Sorting']