|
|
back to boardHints and Solution for late people Hint 1: The teams with same scores follow their original order, top to bottom. Hint 2: You can implement stable sort by yourself. Hint 3: M is given <=100. Hint 4: Group all the teams with the same score together in a container. Solution : Use an array of arrays, with size 101. You can add the input as it comes in the array with the index equal to its score. Output starting from the end, iterating over the array of arrays. C++ Code: #include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<vector<int>> v(101); for(int i =0;i<n;i++) { int a,b; cin >>a >> b; v[b].push_back(a); } for(int i =100;i >= 0;i--) { if((v[i].size())) { for(auto a:v[i]) { cout << a << " " << i << "\n"; } } } return 0; } |
|
|