#include <string> #include <vector> #include <queue> #include <algorithm> using namespace std; int solution(vector<vector<int>> jobs) { int answer = 0; sort(jobs.begin(), jobs.end()); int pos = -1; int count = -1, idx = 0; vector<int> store; priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>> > temp; while(++pos <= jobs[jobs.size() - 1][0] || !temp.empty() || count) { while(idx < jobs.size() && jobs[idx][0] == pos) { temp.push( { jobs[idx][1], pos }); idx++; } if(count <= 0 && !temp.empty()) { count = temp.top().first; store.push_back(temp.top().first + pos - temp.top().second); temp.pop(); } count--; } for(int n : store) { answer += n; } answer /= store.size(); return answer; } | cs |
'problem solving' 카테고리의 다른 글
[BOJ]1874번: 스택 수열 (0) | 2020.03.14 |
---|---|
[LeetCode]#2 Add Two Numbers (0) | 2020.03.14 |
[프로그래머스]섬 연결하기 (0) | 2020.03.13 |
[프로그래머스]이중우선순위큐 (0) | 2020.03.13 |
[미완]디스크 분할 (0) | 2020.03.13 |