#P2803. 学校选址 II
学校选址 II
Description
Along one side of a straight road there are many buildings, each with some primary school students. However, there is no primary school on this road. Therefore, the ever-mischievous "Niu A" plans to choose points on the road to build primary schools (they may coincide with building locations or not), so that the total walking distance of all students is minimized. Since building just one school cannot satisfy his desire for chaos, he decides to build K schools.
Input Format
- The first line contains two integers and , the number of buildings and the number of schools ().
- The second line contains integers, the number of students in each building (each count is between and inclusive).
- The third line contains integers, where the -th number is the distance between building and building (, each distance is between and inclusive).
Output Format
Output the minimal total walking distance of all students.
3 2
24 18 31
10 8
144
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号