MLK - Milk Trading
Hareedi and Hanadt live in a village with N houses built next to each other along one
straight roadway with equal distances between adjacent houses. Some people own cows
and sell the milk their cows produce, while others do not own cows and may need to buy
Every morning, Hareedi and Hanadi transport milk around the village such that everyone
buys or sells the exact number of bottles they want. Transporting one bottle of milk from
one house to an adjacent house results in one unit of work. Fortunately, the number of
milk bottles needed by people is always equal to the number of milk bottles sold by
write a program that is given the number of milk bottles that people at each house needs
to buy or sell, represented as an integer, finds the minimum work necessary to transport
the bottles from sellers to buyers.
2 ≤ N ≤ 1,000,000 The number of houses.
-1000 ≤ Bi ≤ 1000 Integer representing the number of bottles to be bought from or
sold to people at the house at position i.
- Line 1 contains the integer N, the number of houses.
- Each of the next N lines contains an integer Bi. If Bi > 0 then people in house i are cow
owners and want to sell Bi bottles of milk, If Bi ≤ 0 then people at house i are not cow owners
and want to buy Bi bottles of milk.
- A single line containing a single integer, the minimum work units necessary to
transport the bottle of milk.
There are 5 houses as shown in the table.
4 bottles are transported from house 1 to house 2, 1 bottle from house 1 to
house 4, 1 bottle from house 3 to house 4, 1 bottle from house 5 to house 4.
Number of test-cases is 28.
Although time limit seems very thight for that kind of data size, I managed to get AC with scanf. Note that it wasn't the 0.29 time from solutions board, but 2.81 :)
The problem is similar to GERGOVIA with raised constraints and a tighter time limit.