Skip to content

Instantly share code, notes, and snippets.

@surinoel
Created September 22, 2019 01:10
Show Gist options
  • Save surinoel/e6fc2e110725a5c116cbc5c024db1996 to your computer and use it in GitHub Desktop.
Save surinoel/e6fc2e110725a5c116cbc5c024db1996 to your computer and use it in GitHub Desktop.
#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