인프런 커뮤니티 질문&답변
75번 문제 풀이
작성
·
188
1
안녕하세요 강사님.
여름방학부터 코테를 준비하면서 강사님 강의 유익하게 잘 듣고 있습니다.
다름이 아니라 75번 문제 풀이를 구조체 정의하여 푸는 것이 아니라 이전에 알려주신 pair 를 사용하여 풀어도 괜찮을까요?
채점 폴더에 제공된 테스트 케이스는 모두 통과하긴 합니다.
pair를 사용하지 않고 구조체를 따로 정의하고 연산자 오버로딩을 하신 이유가 있는 것 같아 여쭙습니다.
제 풀이 입니다 .
/*
75. 최대 수입 스케쥴(priority_queue 응용문제)
*/
#include
#include
#include
#include
using namespace std;
int main() {
freopen("input.txt", "rt", stdin);
int n, m, d, i;
int dd, tot = 0;
scanf("%d", &n);
// Max Heap
priority_queue<pair<int, int>, vector<pair<int, int> >, less<pair<int, int> > > pQ;
vector<int> sch(n + 1);
for(i = 1; i <= n; i++) {
scanf("%d %d", &m, &d);
pQ.push(make_pair(m, d));
}
while(!pQ.empty()) {
// printf("%d %d\n", pQ.top().first, pQ.top().second);
dd = pQ.top().second;
if(sch[dd] == 0) sch[dd] = pQ.top().first;
else {
while(dd > 1) {
if(sch[--dd] == 0) {
sch[dd] = pQ.top().first;
break;
}
}
}
pQ.pop();
}
for(i = 1; i <= n; i++) {
tot += sch[i];
}
printf("%d\n", tot);
return 0;
}





