#include <string>
#include <vector>
#include <algorithm>
using namespace std;
bool cmp(pair<int, int> a,pair<int, int> b){
if (a.second == b.second)
return a.first < b.first;
else
return a.second < b.second;
}
int solution(vector<vector<int>> jobs) {
int answer = 0;
vector<pair<int, int>> v; //start, worktime
for (int i = 0; i < jobs.size(); i++)
v.push_back(make_pair(jobs[i][0], jobs[i][1]));
sort(v.begin(), v.end(), cmp);
int time = 0, totaltime = 0;
while (!v.size() == 0) {
for (int i = 0; i < v.size(); i++) {
if (time >= v[i].first) {
time += v[i].second;
totaltime = totaltime + time - v[i].first;
v.erase(v.begin() + i);
break;
}
if (i == v.size() - 1)
time++;
}
}
answer = totaltime / jobs.size();
return answer;
}
프로그래머스