My issue
Please , i can’t figure it out , i need answer , i need it in python
My code
#include <bits/stdc++.h>
using namespace std;
int solve() {
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
int res = 1;
priority_queue<int> pq;
for (int i = 0, cur = 0; i < n; i++) {
while (!pq.empty() && cur < i) {
cur += pq.top();
pq.pop();
res++;
}
if (cur < i) return -1;
pq.push(arr[i]);
}
return res;
}
int main() {
// your code goes here
int t;
cin >> t;
while (t--) {
cout << solve() << "\n";
}
return 0;
}
Learning course: Python with Data structures
Problem Link: CodeChef: Practical coding for everyone