我的代码
class Solution {
public:
int eatenApples(vector<int>& apples, vector<int>& days) {
int n = apples.size(), ans = 0;
priority_queue<pair<int, int> > can;
for (int q = 0; ; q++) {
if (q < n) can.push(make_pair(-days[q], q));
int x = can.top().second;
// cout << x << " ";
while (x + days[x] <= q || !apples[x]) {
can.pop();
if (can.empty()) break;
x = can.top().second;
}
if (can.empty() && q >= n) break;
else if (can.empty()) continue;
apples[x]--;
ans++;
}
// puts("");
return ans;
}
};
错误的数据:
apples = [0,4,2,0,1,0,5,6,6,6,1,5,0,1,3,2]
days = [0,3,3,0,2,0,4,4,1,11,2,8,0,1,2,4]
答案应该是19,但我的程序输出的是18
就这一组错了,求助 qaq