Minimum and Maximum
Write Code in Comment
- Subtask #1 (30 points): 2≤N,K≤1,000
- Subtask #2 (70 points): original constraints
Example case 1: To minimise S1, Chef could give 1 chocolate to person 1 and 1 chocolate to person 2, so S1=|1−1|+|1−0|=1.
To maximise S2, Chef can give 1 chocolate to person 1 and 1 chocolate to person 3, since the sequence B=(1,0,1) is a permutation of A=(1,1,0). Then, S2=|1−0|+|0−1|=2.