Created
September 22, 2019 01:10
-
-
Save surinoel/e6fc2e110725a5c116cbc5c024db1996 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <queue> | |
#include <string> | |
#include <vector> | |
using namespace std; | |
int solution(int stock, vector<int> dates, vector<int> supplies, int k) { | |
int answer = 0; | |
int idx = 0; | |
int rstock = stock; | |
priority_queue<int, vector<int>> pq; | |
for (int i = 0; i < k; i++) { | |
if (dates[idx] == i) { | |
pq.push(supplies[idx]); | |
idx += 1; | |
} | |
if (rstock == 0) { | |
answer += 1; | |
rstock += pq.top(); | |
pq.pop(); | |
} | |
rstock--; | |
} | |
return answer; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment