Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <iomanip>
- #include <cstring>
- #include <queue>
- #include <set>
- #include <cmath>
- #define ll long long
- using namespace std;
- int arr[100005];
- int n,d;
- ll p;
- int f(int k){
- priority_queue<int>pq;
- priority_queue<int>iseceni;
- for(int i = 0;i<n;i++){
- pq.push(arr[i]);
- }
- ll sum =0;
- for(int i =1;i<=d;i++){
- int najgolemo = 0;
- if(!pq.empty()) {
- najgolemo = pq.top();
- pq.pop();
- }
- sum+= najgolemo;
- if(i>k and !iseceni.empty()){
- pq.push(iseceni.top());
- iseceni.pop();
- }
- iseceni.push(najgolemo);
- }
- if(sum >= p) return 1;
- else return -1;
- }
- int main() {
- cin >> n >> p >>d;
- for(int i =0;i<n;i++){
- cin >> arr[i];
- }
- int left,right,mid;
- left = 0;
- right = d;
- int res = -1;
- while(left <= right){
- mid = (left+right)/2;
- if(f(mid) == 1){
- left= mid+1;
- res = max(res,mid);
- }
- else if(f(mid) == -1){
- right=mid-1;
- }
- }
- if(res == d){
- cout << "seedno";
- }
- else cout << res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement