- 문제 링크 : boj.kr/29160
- 난이도 : S2
- 태그 : 우선순위 큐
코드
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define INF 0x7FFFFFFF
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll, ll>;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, k;
cin >> n >> k;
priority_queue<int> player[11];
for(int i = 0; i < n; i++) {
int p, w;
cin >> p >> w;
player[p-1].push(w);
}
for(int i = 0; i < 11; i++) {
if(player[i].empty()) continue;
for(int j = 0; j < k; j++) {
int temp = player[i].top(); player[i].pop();
player[i].push(temp-1);
}
}
int ans = 0;
for(int i = 0; i < 11; i++) {
player[i].push(0);
ans += player[i].top();
}
cout << ans;
return 0;
}
풀이
각 포지션을 우선순위 큐를 이용하여 관리해준다.
728x90
'PS' 카테고리의 다른 글
BOJ 11060 : 점프 점프 (0) | 2025.01.22 |
---|---|
BOJ 10866 : 덱 (0) | 2025.01.21 |
BOJ 14940 : 쉬운 최단거리 (0) | 2025.01.19 |
BOJ 15887 : 욱제는 결벽증이야!! (0) | 2025.01.18 |
BOJ 1059 : 좋은 구간 (0) | 2025.01.17 |