|Nộp bài||Các bài nộp||Làm tốt nhất||Về danh sách bài|
BOXES - Boxes
There are n boxes on the circle. The boxes are numbered from 1 to n (1<=n<=1000) in clock wise order. There are balls in the boxes, and the number of all the balls in the boxes is not greater than n.
The balls should be displaced in such a way that in each box there remains no more than one ball. In one move we can shift a ball from one box to one of it's neighboring boxes.
Write a program that: reads from the standard input the number of boxes n and the arrangement of balls in the boxes, computes the minimal number of moves necessary to displace the balls in such a way that in each box there remains no more than one ball, writes the result in the standard output.
The first line of the input file contains an integer t representing the number of test cases (t<=20). Then t test cases follows. Each test case has the following form:
- The first line contains one positive integer n - the number of boxes
- The second line contains n nonnegative integer separated by single spaces. The i-th number is the number of balls in the i-th box.
For each test case, output one nonnegative integer - the number of moves necessary to displace the balls in such a way that in each box there remains no more than one ball.
Input: 1 12 0 0 2 4 3 1 0 0 0 0 0 1 Output: 19
|Được gửi lên bởi:||Jimmy|
|Thời gian chạy:||7.273s|
|Giới hạn mã nguồn:||50000B|
|Cluster:||Cube (Intel G860)|
|Ngôn ngữ cho phép:||Tất cả ngoại trừ: ERL GOSU JS-RHINO NODEJS PERL6 PYPY RUST SED VB.NET|
|Nguồn bài:||III Polish Olympiad in Informatics, stage 3|
Last edit: 2018-10-24 03:23:08
2014-10-27 12:26:18 Nguyễn A
có ai có test và code bài này không cho mình xem với, cảm ơn nhiều
2014-08-30 17:52:59 Kraken
time limit @@!
2014-08-30 17:35:42 Nắng
O(n^3) đủ AC :D