Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int n,m,d;
- long long x[100005],c[100005];
- bool f(long long koj, long long kolku)
- {
- for(int i = 0; i < koj; i++) {
- kolku -= max(0LL, c[i] - x[n - koj + i]);
- if(kolku < 0) {
- return 0;
- }
- }
- return 1;
- }
- int main()
- {
- cin>>n>>m>>d;
- for(int i=0;i<n;i++)
- {
- cin>>x[i];
- }
- for(int i=0;i<m;i++)
- {
- cin>>c[i];
- }
- sort(x,x +n);
- sort(c,c +m);
- int l=0;
- int r=min(n, m);
- int mid=(l+r)/2;
- int maxx = 0;
- while(l<=r)
- {
- mid=(l+r)/2;
- bool ok=f(mid, d);
- if(ok)
- {
- maxx = max(maxx, mid);
- l=mid+1;
- }
- if(!ok)
- {
- r=mid-1;
- }
- }
- mid = maxx;
- cout<<mid<<" ";
- long long sum=0;
- for(int i=0;i<mid;i++)
- {
- sum+=c[i];
- }
- if(sum-d>=0)
- {
- cout<<sum - d;
- }
- else
- {
- cout<<0;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement