Red Huang

Red Huang

Codeforces Round #211 (Div. 2) Renting Bikes

二分法答案即可

/\*  
 \* GCA : "Computer is artificial subject absolutely,Math is God"  
 \*/  
#include <iostream>  
#include <cstdio>  
#include <cstring>  
#include <algorithm>  
#include <cmath>  
#include <climits>  
#include <vector>  
#include <set>  
#include <map>  
#include <queue>  
#include <cctype>  
#include <utility>  
#include <ctime>  
using namespace std;  
#ifdef DEBUG  
#define VAR(a,b) \_\_typeof(b) a=(b)  
#define debug(...) printf("DEBUG: "),printf(\_\_VA\_ARGS\_\_)  
#else  
#define VAR(a,b) \_\_typeof(b) a=(b)  
#define debug(...)  
#endif  
typedef unsigned int uint;  
typedef long long int Int;  
typedef unsigned long long int UInt;  
#define Set(a,s) memset(a,s,sizeof(a))  
#define Pln() printf("\\n")  
#define For(i,x)for(int i=0;i<x;i++)  
#define CON(x,y) x##y  
#define M 100005  
#define PB push\_back  
#define oo INT\_MAX  
#define FOR(a,b) for(VAR(a,(b).begin());a!=(b).end();++a)  
#define eps 1e-9  
#define X first  
#define Y second  
inline bool xdy(double x,double y){return x>y+eps;}  
inline bool xddy(double x,double y){return x>y-eps;}  
inline bool xcy(double x,double y){return x<y-eps;}  
inline bool xcdy(double x,double y){return x<y+eps;}  
const Int mod=1000000007;  
Int n,m,a;  
Int b\[M\];  
Int p\[M\];  
bool great(Int x,Int y){  
    return x>y;  
}  
Int fans=0;  
bool check(Int k){  
    Int ans=0;  
    Int now=a;  
    for(Int i=0;i<k;i++){  
        Int j=k-i-1;  
        if(p\[j\]>b\[i\]){  
            now-=p\[j\]-b\[i\];  
            ans+=b\[i\];  
        }  
        else ans+=p\[j\];  
    }  
    if(now<0)return false;  
    fans=max(ans-now,0LL);  
    return true;  
}  
int main() {  
    ios\_base::sync\_with\_stdio(0);  
    while(~scanf("%I64d%I64d%I64d",&n,&m,&a)){  
        for(Int i=0;i<n;i++)scanf("%I64d",&b\[i\]);  
        for(Int i=0;i<m;i++)scanf("%I64d",&p\[i\]);  
        sort(b,b+n,great);  
        sort(p,p+m);  
        Int r=min(n,m),l=0;  
        while(r>=l){  
            Int mid=(r+l)>>1;  
            if(check(mid)){  
                l=mid+1;  
            }else{  
                r=mid-1;  
            }  
        }  
        printf("%I64d %I64d\\n",r,fans);  
    }  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
}  

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.