-
Notifications
You must be signed in to change notification settings - Fork 0
/
Programmers_실패율.cpp
46 lines (40 loc) · 957 Bytes
/
Programmers_실패율.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
bool cmp(const pair<int, double> &u, const pair<int, double> &v) {
if (u.second == v.second) {
return u.first < v.first;
}
return u.second < v.second;
}
vector<int> solution(int N, vector<int> stages) {
vector<int> ans;
vector<pair<double, double>> score(N + 1, make_pair(0, 0));
for (int i = 0; i < stages.size(); i++) {
int p = stages[i];
if (p != N + 1) {
score[p].second += 1;
}
for (int j = p - 1; j >= 1; j--) {
score[j].first += 1;
score[j].second += 1;
}
}
vector<pair<int, double>> tmp(N + 1, make_pair(0, 0));
for (int i = 1; i <= N; i++) {
tmp[i].first = i;
if(score[i].second != 0) {
tmp[i].second = score[i].first / score[i].second;
}
else {
tmp[i].second = 1;
}
}
sort(tmp.begin() + 1, tmp.end(), cmp);
for (int i = 1; i <= N; i++) {
ans.push_back(tmp[i].first);
}
return ans;
}