{"name":"john", "designation": "plumber"}, this is an example of
JSON data
XML data
meta data
header Data
Answers
Answer:
Each student is identified by a unique Roll Number (r[i]) and a Unique Identification Number(a[i]). The total amount of the trip will be calculated as the sum of the cost of each of the rounds as long as there are at least two students remaining in the class. In a single round:
• Professor will select two students in his class, let them be p and q.
• Choose Unique Identification Number(a[p]) of one and Roll Number(r[q]) of the other. Add the value a[p] * r[q] to the amount of trip. Or another option is vice versa, a[q] * r[p]
• Return one (say p) back to the class, while the other (say q) will go and sit in the bus outside or vice versa, i.e., return q to the class and p goes and sits in the bus. Note p and q are indexes of the students.
In the last round, both students will go to the bus.
The professor needs your help. You need to find the minimum possible amount of the trip, considering all the possible ways in which the student can be selected and organized. Help him out.
As this amount can be very large find its mod with 10^9+7.
Input
• The first line contains a positive integer n: the number of students.
• The second line contains a list of N positive integers a; the i-th of these represents the Unique Identification Number on the i-th student.
• The third line contains a list of N positive integers r; the i-th of these represents the Roll number on the i-th student.
Output
The minimum possible total that can be attained if students are selected optimally.
Constraints
1<=n<=10^3
1<=a[i]<=10^9
1<=r[i]<=10^5
Sample test case
3
23 45 56
11 14 3
Explanation:
Professor X will first select student1 and student3, adding the value (a[1] * r[3]) i.e 23 * 3 = 69 to the total. student1 will go and sit in the bus while student3 will return back to the class. In the next round, professor will select the remaining students i.e student2 and student3. He will be adding the value (a[2] * r[3]) i.e 45 * 3 = 135 to the total. After this, no more pairs of students will remain in the class so the minimum possible amount will be 69 + 135 = 204.
• [execution time limit] 3 seconds (java)
• [input] integer n
• [input] array.integer64 a
• [input] array.integer64 r
• [output] integer64
[Java] Syntax Tips
// Prints help message to the console
// Returns a string
//
// Globals declared here will cause a compilation error,
// declare variables inside the function instead!
String helloWorld(String name) {
System.out.println("This prints to the console when you Run Tests");
return "Hello, " + name;
}