Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <queue>
- using namespace std;
- typedef long long ll;
- const int maxn = 1e5 + 10;
- int n, d;
- ll P;
- ll a[maxn];
- bool check(int K) {
- priority_queue<ll> pq, greatest;
- for(int i = 0; i < n; i++) {
- pq.push(a[i]);
- }
- ll sum = 0;
- for(int i = 1; i <= d; i++) {
- ll max_element = 0;
- if(!pq.empty()) {
- max_element = pq.top();
- pq.pop();
- }
- sum += max_element;
- if(i > K) {
- pq.push(greatest.top());
- greatest.pop();
- }
- greatest.push(max_element);
- }
- if(sum >= P) {
- return true;
- }
- return false;
- }
- int main() {
- cin >> n >> P >> d;
- for(int i = 0; i < n; i++) {
- cin >> a[i];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment