weights[i] is the weight of parcel i. You must cut the belt into groups non-empty groups, each a contiguous stretch of the belt (the order of parcels cannot change).
The score of a group is the weight of its first parcel plus the weight of its last parcel (a single-parcel group counts its weight twice). The score of a split is the sum of the scores of all its groups.
Return the difference between the largest and the smallest score over all possible splits.weights=[2, 6, 1, 4], groups=2 → 3
Cut after parcel 0: (2 + 2) + (6 + 4) = 14; after parcel 1: (2 + 6) + (1 + 4) = 13; after parcel 2: (2 + 1) + (4 + 4) = 11. Max 14, min 11, difference 3.
weights=[5, 9, 3], groups=3 → 0
Every parcel forms its own group, so there is only one split and the difference is 0.
weights=[1, 8, 2, 7, 3], groups=3 → 2
weights=[2, 6, 1, 4], groups=2
3
Run checks the first 3 tests in your browser. Submit checks all 90 tests on the server, hidden ones included.