Strange Grid
InterviewTime limit1sMemory limit1024 MB
Given N people on a grid where each direction has its own movement cost, find the minimum total cost for everyone to gather at one cell.
- Level
Medium5 of 10
- Topics
- Sorting, Prefix sum, Math
- Solved
- No attempts yet
Problem
On a strange grid, every move to an adjacent cell costs health. Moving from to costs , to costs , to costs , and to costs .
people are scattered across the grid. What is the minimum total health they must spend to gather at a single point?
Input
The first line contains , , , , in that order. (, )
From the second line, lines follow, each with the integer coordinates , of one person on the grid, in order. ()
All numbers in the input are integers.
Output
Print the answer on the first line.