http://codeforces.com/contest/363/problem/D
先对b和p排序,用二分求出可以租的车子的最大辆数,其中用mid以后的个人钱数去租前mid的价钱的车子。
1 #include2 #include 3 #include 4 #define LL __int64 5 #define N 200000 6 using namespace std; 7 int n,m; 8 LL a; 9 LL p[N],b[N];10 int max1;11 12 bool ok(int mid)13 {14 LL sum=0;15 for(int i=0; i =p[i]) continue;18 else if(p[i]>b[n-mid+i])19 {20 sum+=(p[i]-b[n-mid+i]);21 }22 }23 if(sum>a) return false;24 return true;25 }26 27 int main()28 {29 while(scanf("%d%d%I64d",&n,&m,&a)!=EOF)30 {31 for(int i=0; i >1;46 if(ok(mid))47 {48 l=mid+1;49 max1=max(max1,mid);50 }51 else52 {53 r=mid-1;54 }55 }56 if(max1==0)57 {58 printf("0 0\n");59 continue;60 }61 else62 {63 LL ans=0;64 for(int i=0; i =ans)69 {70 printf("%d %d\n",max1,0);71 }72 else73 {74 printf("%d %I64d\n",max1,ans-a);75 }76 }77 }78 return 0;79 }