SPOJ FASHION

From Algorithmist
Jump to navigation Jump to search

1025 - Fashion Shows[edit]

Summary[edit]

Given the "hotness" level of the male/female, print the total hotness of the group.

Explanation[edit]

You are given two rows of integers. After sorting, multiply the two numbers in each "column" and add them to a running total for the test case.

Gotchas[edit]

Notes[edit]

Implementations[edit]

import java.util.*;

public class Main {

public static void main(String[] args) {

Scanner s =new Scanner(System.in);

int c=0, casos=s.nextInt();

while (c<casos) {

int v1[]=new int[s.nextInt()];

for (int i = 0; i < v1.length; i++) {

v1[i]=s.nextInt();

}

int cont=0;int v2[]=new int[v1.length];

for (int i = 0; i < v2.length; i++) {

v2[i]=s.nextInt();

}

Arrays.sort(v1);

Arrays.sort(v2);

for (int i = 0; i < v2.length; i++) {

cont+=v1[i]*v2[i];

}

System.out.println(cont);


c++;

}

}

} by Jack Ibarra



C++ version using insertion sort at

http://ideone.com/ajCq86

by reggaeguitar

Optimizations[edit]

Input[edit]

2
2
1 1
3 2
3
2 3 2
1 3 2

Output[edit]

5
15

References[edit]

  1. Reference 1

Categories here, use the form [[Category: Category Name]], see Categories for a list