-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMinimumScalarProduct.java
More file actions
58 lines (53 loc) · 1.3 KB
/
MinimumScalarProduct.java
File metadata and controls
58 lines (53 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//Created by Sidhant
//3-04-2017
//Implementation of minimum scalar product
import java.util.*;
public class min
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
System.out.println("Enter the number of cases");
int x=in.nextInt();
int n,temp,sum=0;
for(int i=0;i<x;i++)
{
sum=0;
n=in.nextInt();
int a[]=new int[n];
int b[]=new int[n];
for(int j=0;j<n;j++)
{
a[j]=in.nextInt();
}
for(int j=0;j<n;j++)
{
b[j]=in.nextInt();
}
for(int j=0;j<n-1;j++)
{
for(int k=j+1;k<n;k++)
{
if(a[j]>a[k])
{
temp=a[j];
a[j]=a[k];
a[k]=temp;
}
if(b[j]<b[k])
{
temp=b[j];
b[j]=b[k];
b[k]=temp;
}
}
}
for(int j=0;j<n;j++)
{
// System.out.println(a[j]);
sum=sum+(a[j]*b[j]);
}
System.out.println(sum);
}
}
}