[Programmers] 라면공장

Time Lapse :19min 27sec

solution.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <string>
#include <vector>
#include <queue>
using namespace std;
//19:27
int solution(int stock, vector<int> dates, vector<int> supplies, int k) {
priority_queue<int,vector<int>,less<int>> pq;
int idx = 0;
int answer = 0;
for(int i=0;i<k;i++){
if(stock==0){
for(;dates[idx]<=i;idx++)
pq.push(supplies[idx]);

stock += pq.top();
pq.pop();
++answer;
}
--stock;
}
return answer;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/Programmers/ramenFactory/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.