[ 문제 ]
[ 접근방법 ]
먼저 새로운 점수가 랭킹 리스트에 올라갈 수 있는지 판별한다 ( cnt1 ).
그 후, 랭킹 리스트에 몇 등으로 올라가는지 구한다 ( cnt2 ).
[ 소스코드 ]
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n, s, p;
vector<int> score;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> s >> p;
score.resize(n);
for (int i = 0; i < n; i++)
{
cin >> score[i];
}
score.push_back(s);
sort(score.begin(), score.end(), greater<int>());
int cnt1 = upper_bound(score.begin(), score.end(), s, greater<int>()) - score.begin();
int cnt2 = lower_bound(score.begin(), score.end(), s, greater<int>()) - score.begin() + 1;
cout << (cnt1 > p ? -1 : cnt2);
return 0;
}
'PS' 카테고리의 다른 글
[ 백준 / C++ ] 1446 : 지름길 (0) | 2025.02.05 |
---|---|
[ 백준 / C++ ] 19941 : 햄버거 분배 (0) | 2025.02.04 |
[ 백준 / C++ ] 1038 : 감소하는 수 (0) | 2025.01.23 |
[ 백준 / C++ ] 1197 : 최소 스패닝 트리 (0) | 2025.01.21 |
[ 백준 / C++ ] 2965 : 캥거루 세마리 (0) | 2025.01.15 |