Josif_tepe

Untitled

Jan 21st, 2026
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <queue>
  4. using namespace std;
  5.  
  6. typedef long long ll;
  7. const int maxn = 1e5 + 10;
  8. int n, d;
  9. ll P;
  10.  
  11. ll a[maxn];
  12.  
  13. bool check(int K) {
  14.     priority_queue<ll> pq, greatest;
  15.     for(int i = 0; i < n; i++) {
  16.         pq.push(a[i]);
  17.     }
  18.    
  19.     ll sum = 0;
  20.     for(int i = 1; i <= d; i++) {
  21.         ll max_element = 0;
  22.         if(!pq.empty()) {
  23.             max_element = pq.top();
  24.             pq.pop();
  25.         }
  26.        
  27.         sum += max_element;
  28.         if(i > K) {
  29.             pq.push(greatest.top());
  30.             greatest.pop();
  31.         }
  32.        
  33.         greatest.push(max_element);
  34.        
  35.     }
  36.    
  37.     if(sum >= P) {
  38.         return true;
  39.     }
  40.     return false;
  41.    
  42. }
  43. int main() {
  44.    
  45.     cin >> n >> P >> d;
  46.     for(int i = 0; i < n; i++) {
  47.         cin >> a[i];
  48.     }
  49.    
  50.    
  51.    
  52.    
  53.    
  54. }
  55.  
  56.  
  57.  
  58.  
  59.  
Advertisement
Add Comment
Please, Sign In to add comment