본문 바로가기

problem solving

[미완]디스크 분할

#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <iostream>
 
using namespace std;
 
int solution(vector<vector<int>> jobs) {
    int answer = 0;
    
    int pos = -1;
    int count = 0, idx = 0;
    vector<int> store;
    priority_queue<pair<intint>vector<pair<intint>>, greater<pair<intint>> > temp;
    while(++pos < jobs.size() || count) {
        if(idx < jobs.size() && jobs[idx][0== pos) {
            temp.push( { jobs[idx][1- pos, pos });
            idx++;
            // cout << pos <<  "\n";
        }
        
        count--;
        
        if(count <= 0 && !temp.empty()) {
            count = temp.top().first + temp.top().second;
            store.push_back(temp.top().second + temp.top().first + pos - temp.top().second);
            // cout << temp.top().second << ", " << temp.top().first  << ", " << temp.top().second + temp.top().first + pos - tem             p.top().second << "\n";
            temp.pop();
        }
    }
    
    
    // while(!temp.empty()) {
    //     cout << temp.top().first << "\n";
    //     temp.pop();
    // }
    
    for(int idx = 0; idx < store.size(); idx++) {
        answer += store[idx];
    }
    answer /= store.size();
    return answer;
}
cs

'problem solving' 카테고리의 다른 글

[프로그래머스]섬 연결하기  (0) 2020.03.13
[프로그래머스]이중우선순위큐  (0) 2020.03.13
[프로그래머스]라면공장  (0) 2020.03.13
[프로그래머스]라면공장  (0) 2020.03.13
[프로그래머스]여행경로  (0) 2020.03.13