Armor Hall
InterviewTime limit2sMemory limit1024 MB
Given weighted points on a line, find the integer position that minimizes total weighted distance, taking the smallest coordinate on ties.
- Level
Medium4 of 10
- Topics
- Prefix sum, Array, Greedy
- Solved
- No attempts yet
Problem
Tony Stark is setting up a new armor hall, a straight line with compartments for iron suits at some of its points. Tony wants to pick a point above which to build a takeoff hatch. The suits fly to Stark on their own, but he does not like waiting, so the hatch must be placed at an integer point where the total distance to all suits is the smallest. If several points tie, he wants the one with the smallest coordinate. Write a program for Jarvis that finds the optimal point for the hatch.
Input
The first line contains a single positive integer , the number of points with iron suit compartments (). The second line contains integers , the number of suits in the -th compartment (). The third line contains integers , the coordinate of the -th compartment (). More than one compartment can share a coordinate. It is guaranteed that for every .
Output
Print one integer, the optimal point for placing the hatch.