[Programmers] 디스크 컨트롤러

Time Lapse :19min 33sec

solution.cpp

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
32
33
34
35
36
37
38
39
40
41
#include <string>
#include <vector>
#include <algorithm>
//19:33
using namespace std;
bool mysort(vector<int> v1, vector<int> v2){
if(v1[0]<v2[0])
return true;
else if(v1[0]==v2[0]){
if(v1[1]<v2[1])
return true;
}
return false;
}
int solution(vector<vector<int>> jobs) {
sort(jobs.begin(),jobs.end(),mysort);
int answer = 0;
int size = jobs.size();
int start_time=0;
while(jobs.size()!=0){
int choose = 987654321;
int during_time = 987654321;
for(int i=0;i<jobs.size();i++){
if(jobs[i][0]>start_time)
break;
if(during_time>jobs[i][1]){
choose = i;
during_time = jobs[i][1];
}
}
if(choose<500){
answer += jobs[choose][1]+start_time-jobs[choose][0];
start_time += jobs[choose][1];
jobs.erase(jobs.begin()+choose);
}
else{
++start_time;
}
}
return answer/size;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/Programmers/diskController/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.