题解

1 条题解

  • 1
    @ 2022-08-20 15:16:36
    #include "iostream"
    #include "cstdlib"
    #include "cstdio"
    #include "cstring"
    #include "algorithm"
    using namespace std;
    #define MAXN 10005
    struct Node{
        int a,b,c;
        friend bool operator<(const Node &x, const Node &y){
            if(x.a<x.b&&y.a<y.b){
                if(x.a==y.a)return x.c<y.c;
                return x.a<y.a;
            }
            else if(x.a>x.b&&y.a>y.b){
                if(x.b==y.b)return x.c<y.c;
                return x.b>y.b;
            }
            else if(x.a==x.b&&y.a==y.b)
                return x.c<y.c;
            else if(x.a<x.b)return true;
            else if(y.a<y.b)return false;
            else return x.a==x.b;
        }
    }x[MAXN];
    int n;
    int main(){
        freopen("prod.in","r",stdin);
        freopen("prod.out","w",stdout);
        scanf("%d",&n);
        for(int i=1;i<=n;++i)scanf("%d",&x[i].a),x[i].c=i;
        for(int i=1;i<=n;++i)scanf("%d",&x[i].b);
        sort(x+1,x+n+1);
        int tb=0,ta=0;
        for(int i=1;i<=n;++i){
            ta+=x[i].a;
            tb=max(ta,tb)+x[i].b;
        }
        cout << tb << endl;
    //  for(int i=1;i<=n;++i)
    //      printf("%d%c",x[i].c," \n"[i==n]);
        return 0;
    }
    
  • 1

信息

ID
1564
难度
6
分类
贪心 点击显示
标签
递交数
3
已通过
1
通过率
33%
上传者