#include <bits/stdc++.h>
using namespace std;
vector <pair <int, string>> scores;
bool comp(const pair <int, string> &a, const pair <int, string> &b) {
if (a.first == b.first)
return a.second < b.second;
return a.first > b.first;
}
int main() {
int n;
cin >> n;
map <string, int> mp;
scores.resize(n);
for (int i = 0; i < n; i++) {
string s;
cin >> s;
scores[i].second = s;
mp[s] = i;
for (int j = 0; j < 5; j++) {
int x;
cin >> x;
scores[i].first -= x;
}
}
sort(scores.begin(), scores.end());
multiset <pair <int, string>, bool (*)(const pair <int, string> &, const pair <int, string> &)> scores2(comp);
for (int i = 0; i < n; i++) {
scores[i].first = -scores[i].first;
scores2.insert(scores[i]);
}
vector <pair <int, int>> ans(n);
for (int i = 0; i < n; i++) {
string name = scores[i].second;
int id = mp[name];
pair <int, string> tp = scores[i];
scores2.erase(tp);
tp.first += 500;
scores2.insert(tp);
auto it = scores2.begin();
for (int j = 0; j < n; j++) {
if (it->second == name) {
ans[id].first = j+1;
break;
}
it++;
}
scores2.erase(tp);
tp.first -= 1000;
scores2.insert(tp);
it = scores2.begin();
for (int j = 0; j < n; j++) {
if (it->second == name) {
ans[id].second = j+1;
break;
}
it++;
}
scores2.erase(tp);
tp.first += 500;
scores2.insert(tp);
}
for (int i = 0; i < n; i++)
cout << ans[i].first << ' ' << ans[i].second << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Correct |
3 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
3 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |