求两组数组一一对应相乘后和的最大值。。。换一下语风。。
#include<cstring> #include<iostream> #include<algorithm> using namespace std; int n,t,i,j,ans,x; int a[1005],b[1005]; int main(){ cin>>t; while(t--){ ans=0; cin>>n; for (i=1;i<=n;i++) cin>>a[i]; for (i=1;i<=n;i++) cin>>b[i]; sort(a+1,a+n+1); sort(b+1,b+n+1); for (i=1;i<=n;i++) ans+=a[i]*b[i]; cout<<ans<<endl; } }