#include<iostream>
#include<algorithm>
using namespace std;
bool soj(int a,int b){
return a>b;
}
bool sos(int a,int b){
return a<b;
}
int main(){
int t,n;
int sum;
cin>>t;
for(int i=0;i<t;i++){
sum=0;
cin>>n;
int a[n],b[n];
for(int j=0;j<n;j++)cin>>a[j];
for(int j=0;j<n;j++)cin>>b[j];
sort(a,a+n,sos);
sort(b,b+n,soj);
for(int j=0;j<n;j++)
sum+=a[j]*b[j];
cout<<sum<<endl;
}
return 0;
}
Two nature of knowledge is the same. Each edge has k are weights (typically k = 2), is now to take a set of M such that the sides of all the communication points, and minimizes the sum of the product ...
Single point time limit: 2.0 sec Memory limit: 256 MB You are given two vectors v1=(x1,x2,…,xn) and v2=(y1,y2,…,yn). The scalar product of these vectors is a single number, calculated as...
Tick ticking---topic link You are given two vectors v1=(x1,x2,…,xn)v1=(x1,x2,…,xn) and v2=(y1,y2,…,yn)v2=(y1,y2,…,yn). The scalar product of these ve...
Description Give two groups, each n. Please adjust the order of each group so that the two sets of data are multiplied by the same subscript elements, and then the sum of the sums is the smallest. The...
Title Description Given n points weighted directed graph, find the path from 1 to n of the product of the smallest edge weights of simple paths. Input Format The first line reads two integers n...
topic: You are given two vectors v1=(x1,x2,...,xn) and v2=(y1,y2,...,yn). The scalar product of these vectors is a single number, calculated as x1y1+x2y2+...+xnyn. Suppose you are allowed to permute t...
Training Algorithm smallest product (basic) Time limit: 1.0s Memory Limit: 512.0MB Problem Description A number of groups, each of n. adjust the order number of each group, such that the...
Luogu5540 minimum product spanning tree Topic links:Luo Valley Topic Description: For a\(n\)Points\(m\)FIG undirected of edges, each edge has two edge weight\(a_i,b_i\), Seeking the\((\sum a_i)\times ...
Problem Description Give two sets of numbers, n each. Please adjust the order of the number of each group so that the same subscript elements of the two groups of data are correspondingly multiplied, ...