zoukankan      html  css  js  c++  java
  • D. Renting Bikes 二分

    D. Renting Bikes
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    A group of n schoolboys decided to ride bikes. As nobody of them has a bike, the boys need to rent them.

    The renting site offered them m bikes. The renting price is different for different bikes, renting the j-th bike costs pj rubles.

    In total, the boys' shared budget is a rubles. Besides, each of them has his own personal money, the i-th boy has bi personal rubles. The shared budget can be spent on any schoolchildren arbitrarily, but each boy's personal money can be spent on renting only this boy's bike.

    Each boy can rent at most one bike, one cannot give his bike to somebody else.

    What maximum number of schoolboys will be able to ride bikes? What minimum sum of personal money will they have to spend in total to let as many schoolchildren ride bikes as possible?

    Input

    The first line of the input contains three integers nm and a (1 ≤ n, m ≤ 1050 ≤ a ≤ 109). The second line contains the sequence of integers b1, b2, ..., bn (1 ≤ bi ≤ 104), where bi is the amount of the i-th boy's personal money. The third line contains the sequence of integers p1, p2, ..., pm (1 ≤ pj ≤ 109), where pj is the price for renting the j-th bike.

    Output

    Print two integers r and s, where r is the maximum number of schoolboys that can rent a bike and s is the minimum total personal money needed to rent r bikes. If the schoolchildren cannot rent any bikes, then r = s = 0.

    Sample test(s)
    input
    2 2 10
    5 5
    7 6
    output
    2 3
    input
    4 5 2
    8 1 1 2
    6 3 7 5 2
    output
    3 8
    Note

    In the first sample both schoolchildren can rent a bike. For instance, they can split the shared budget in half (5 rubles each). In this case one of them will have to pay 1 ruble from the personal money and the other one will have to pay 2 rubles from the personal money. In total, they spend 3 rubles of their personal money. This way of distribution of money minimizes the amount of spent personal money.

    二分找最大的车数。。。。。

    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<cmath>
    #include<algorithm>
    #include<string>
    #include<map>
    #include<stack>
    #include<set>
    #include<iostream>
    #include<vector>
    #include<queue>
    //ios_base::sync_with_stdio(false);
    //#pragma comment(linker, "/STACK:1024000000,1024000000")
    
    using namespace std;
    #define sz(v) ((int)(v).size())
    #define rep(i, a, b) for (int i = (a); i < (b); ++i)
    #define repf(i, a, b) for (int i = (a); i <= (b); ++i)
    #define repd(i, a, b) for (int i = (a); i >= (b); --i)
    #define clr(x) memset(x,0,sizeof(x))
    #define clrs( x , y ) memset(x,y,sizeof(x))
    #define out(x) printf(#x" %d
    ", x)
    #define sqr(x) ((x) * (x))
    typedef long long LL;
    
    const int INF = 1000000000;
    const double eps = 1e-8;
    const int maxn = 300000;
    int b[maxn];
    int p[maxn];
    int main() 
    {
        //freopen("in.txt","r",stdin);
        int n,m,a;
        while(cin>>n>>m>>a)
        {
            repf(i,1,n)
                scanf("%d",&b[i]);
            
            repf(i,1,m)
                scanf("%d",&p[i]);
            
            int ans = 0;
            sort(b+1,b+1+n);
            sort(p+1,p+1+m);
            
            int Min = min(n,m);
            int L = 0;
            int R = Min;
            int mid;
            while(L <= R)
            {
                int temp = a;
                mid = (L+R)/2;
                int i;
                for(i = n-mid +1;i<=n;++i)
                {
                    int gap = p[i - (n-mid+1)+1] - b[i];
                    if(gap > 0)
                    {
                        if(temp>=gap)
                        {
                            temp-=gap;
                        }else
                        {
                            break;
                        }
                    }
                }
                if(i == n+1)
                {
                    L = mid + 1;
                }else
                    R = mid - 1;
            }
            
            repf(i,1,R)
                ans+=p[i];
            cout<<R<<" "<<max(0,ans - a)<<endl;
        }
        return 0;
    }
  • 相关阅读:
    Maidsafe-去中心化互联网白皮书
    The Top 20 Cybersecurity Startups To Watch In 2021 Based On Crunchbase
    Top 10 Blockchain Security and Smart Contract Audit Companies
    The 20 Best Cybersecurity Startups To Watch In 2020
    Blockchain In Cybersecurity: 11 Startups To Watch In 2019
    004-STM32+BC26丨260Y基本控制篇(阿里云物联网平台)-在阿里云物联网平台上一型一密动态注册设备(Android)
    涂鸦开发-单片机+涂鸦模组开发+OTA
    000-ESP32学习开发-ESP32烧录板使用说明
    03-STM32+Air724UG远程升级篇OTA(阿里云物联网平台)-STM32+Air724UG使用阿里云物联网平台OTA远程更新STM32程序
    03-STM32+Air724UG远程升级篇OTA(自建物联网平台)-STM32+Air724UG实现利用http/https远程更新STM32程序(TCP指令,单片机程序检查更新)
  • 原文地址:https://www.cnblogs.com/DreamHighWithMe/p/3418522.html
Copyright © 2011-2022 走看看