티스토리 뷰

최대수입 스케줄

#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
struct Data {
	int money;
	int when;
	Data(int a, int b){
		money=a;
		when=b;
	}
	bool operator<(Data &b){
		return when>b.when;
	}
};
int main() {
	freopen("input.txt", "rt", stdin);
	int a, b, i, j, n, res=0, max=-2147000000;
	priority_queue<int> pQ;
	vector<Data> T;
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d %d", &a, &b);
		T.push_back(Data(a, b));
		if(b>max){
			max=b;
		}
	}
	sort(T.begin(), T.end());
	j=0;
	for(i=max; i>0; i--){
		for( ; j<=n; j++){
			if(T[j].when<i) break;
			pQ.push(T[j].money);
		}
		if(!pQ.empty()){
			res+=pQ.top();
			pQ.pop();			
		}
	}
	printf("%d", res);	
	return 0;
}
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/01   »
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
글 보관함