problem solving
[프로그래머스]디스크 컨트롤러
Shinuk Yi
2020. 3. 14. 07:52
#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 |