1 条题解

  • 0
    @ 2022-10-9 8:31:13

    C++ :

    #include <bits/stdc++.h>
    #define int long long
    #define pb push_back
    #define fer(i,a,b) for(int i=a;i<=b;++i)
    #define der(i,a,b) for(int i=a;i>=b;--i)
    #define all(x) (x).begin(),(x).end()
    #define pll pair<int,int>
    #define et  cout<<'\n'
    #define xx first
    #define yy second
    using namespace std;
    template <typename _Tp>void input(_Tp &x){
        char ch(getchar());bool f(false);while(!isdigit(ch))f|=ch==45,ch=getchar();
        x=ch&15,ch=getchar();while(isdigit(ch))x=x*10+(ch&15),ch=getchar();
        if(f)x=-x;
    }
    template <typename _Tp,typename... Args>void input(_Tp &t,Args &...args){input(t);input(args...);}
    vector<pll> v;
    
    signed main(){
        int A,B,n,m,k;
        input(A,B,n,m,k);
        int x;
        fer(i,1,n){
            cin>>x;
            v.pb({x,1});
        }
        fer(i,1,m){
            cin>>x;
            v.pb({x,2});
        }
        fer(i,1,k){
            cin>>x;
            v.pb({x,0});
        }
        sort(v.begin(),v.end(),greater<pll>());
        int sum=0;
        int res=0;
        int jian=0,nu=0;
    
        for(auto t:v){
            if(t.second==1){
                if(jian<A){
                    res+=t.first;
                    jian++;
                    sum++;
                }
            }
            else if(t.second==2){
                if(nu<B){
                    res+=t.first;
                    nu++;
                    sum++;
                }
            }
            else{
                res+=t.first;
                sum++;
            }
    
            if(sum==A+B) break;
        }
        cout<<res<<endl;
    }
    

    Python :

    # coding=utf-8
    s=sorted;(x,y,*_),a,b,c=eval('map(int,input().split()),'*4)
    print(sum(s(s(a)[-x:]+s(b)[-y:]+[*c])[-x-y:]))
    
    • 1

    信息

    ID
    12835
    时间
    2000ms
    内存
    1024MiB
    难度
    7
    标签
    递交数
    141
    已通过
    30
    上传者