#include<iostream> #include<algorithm> using namespace std; struct m{ int a; int b; }; struct m N[1001],N1[1001],N2[1001]; int n; bool cmp1(m x,m y){ return x.a<y.a; } bool cmp2(m x,m y){ return x.b>y.b; } int main(){ while(cin>>n){ int t1=0,t2=0; for(int i=1;i<=n;i++) cin>>N[i].a; for(int i=1;i<=n;i++) cin>>N[i].b; for(int i=1;i<=n;i++) { if(N[i].a<=N[i].b){ N1[++t1].a=N[i].a; N1[t1].b=N[i].b; } else { N2[++t2].a=N[i].a; N2[t2].b=N[i].b; } } sort(N1+1,N1+t1+1,cmp1); sort(N2+1,N2+t2+1,cmp2); int f1=0,f2=0; for(int i=1;i<=t1;i++){ f1+=N1[i].a; f2=max(f2,f1)+N1[i].b; } for(int i=1;i<=t2;i++){ f1+=N2[i].a; f2=max(f2,f1)+N2[i].b; } cout<<f2<<endl; } return 0; }
标签:std,struct,加工,int,问题,生产,include,1001 From: https://www.cnblogs.com/lhf123/p/17328907.html