Minimum product

#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;
} 

Intelligent Recommendation

The minimum spanning tree and the product of the maximum matching minimum product

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 ...

EOJ#2183 Minimum Scalar Product (Minimum Scalar 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...

Minimum Scalar Product Kattis - minimumscalar

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...

Algorithm to improve the minimum product (increased)

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...

More Recommendation

codecomb 2090] [minimum product passage

  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...

Minimum Scalar Product HRBUST - 1754

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...

Minimum product training algorithm (Basic)

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

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 ...

Algorithm training Minimum product (basic)

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, ...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top