Humanities and Arts Exploration Week
InterviewTime limit2sMemory limit512 MB
Given N tree positions and Q query points, output for each query the sum of absolute distances to all trees.
- Level
Medium4 of 10
- Topics
- Sorting, Prefix sum, Binary search, Math
- Solved
- No attempts yet
Problem
Taeyoung is spending "Humanities and Arts Exploration Week," SASA's festival. He went to Sejong Lake Park for the occasion and was struck by how beautiful the scenery was.
Sejong Lake Park stretches out in a straight line. The park has trees in total, and the position of the -th tree is .
Taeyoung wants to capture this beautiful scenery by taking panoramic photos with his camera. He wants to give each photo a score, and the score of a photo is the sum of the distances from the position where the photo was taken to each tree. The distance between two positions is defined as the absolute value of their difference.
For each photo Taeyoung took, find its score.
Input
The first line gives the number of trees and the number of photos Taeyoung took , separated by a space.
The second line gives the positions of the trees .
Among the lines starting from the third line, the -th line gives , the position where Taeyoung took his -th photo.
Output
On the -th line, print the score of the -th photo Taeyoung took, one per line in order.
Constraints
- ()
- ()
- All numbers given in the input are integers.