最小乘积(提高型)

code

#include<iostream>
#include<algorithm>
using namespace std;
const int N=1000+10;
bool cmp(int x,int y){
	return x>y;
}
int f1[N],f2[N];
int main(){
	ios::sync_with_stdio(false);
	int tot,len;
	cin>>tot;
	while(tot--){
		//TODO
		int s=0;
		cin>>len;
		for(int i=0;i<len;i++){
			cin>>f1[i];
		}
		for(int i=0;i<len;i++){
			cin>>f2[i];
		}
		sort(f1,f1+len);
		sort(f2,f2+len,cmp);
		for(int i=0;i<len;i++){
			s+=f1[i]*f2[i];
		}
		cout<<s<<'\n';
	}
	return 0;
}
posted @ 2022-02-11 15:43  ethon-wang  阅读(37)  评论(0编辑  收藏  举报