#P12545. [UOI 2025] Partitioning into Three

[UOI 2025] Partitioning into Three

题目描述

There are nn non-negative integers a1,a2,,ana_1, a_2, \ldots, a_n arranged in a circle. The neighboring numbers in the circular order are a1a_1 and a2a_2, a2a_2 and a3a_3, \ldots, an1a_{n-1} and ana_n, ana_n and a1a_1.

Partition these numbers into three non-empty groups such that each number belongs to exactly one group, the numbers in each group are consecutively arranged in a circle, and the difference between the maximum and minimum sums of the numbers in the groups is minimized.

输入格式

The first line contains one integer nn (3n106)(3 \le n \le 10^6) --- the number of arranged numbers.

The second line contains nn non-negative integers a1,a2,,ana_1, a_2, \ldots, a_n (0ai109)(0 \le a_i \le 10^9) --- the numbers arranged in a circle.

输出格式

In the first line, output one integer --- the difference between the maximum and minimum sums of the numbers in the groups in the optimal partition.

In the second line, output three integers xx, yy, zz (1x<y<zn)(1 \le x < y < z \le n) --- such indices that the optimal partition of the numbers into three groups is of the form [ax,ax+1,,ay1][a_{x}, a_{x+1}, \ldots, a_{y-1}], [ay,ay+1,,az1][a_{y}, a_{y+1}, \ldots, a_{z-1}], $[a_{z}, a_{z+1}, \ldots, a_{n-1}, a_{n}, a_{1}, a_{2}, \ldots, a_{x-1}]$.

If there are multiple correct answers, any of them is allowed to be output.

4
1 2 3 4
1
1 3 4
7
1 6 1 0 5 3 2
0
2 3 6
8
3 1 4 1 5 9 2 6
1
3 6 8

提示

In the third example, the optimal partition looks as follows:

In this case, the sums in the groups are 1010, 1111, and 1010.

Scoring

  • (22 points): n=3n = 3;
  • (44 points): ai1a_i \le 1 for 1in1 \le i \le n;
  • (1313 points): there exists a partition where the sought difference is equal to 00;
  • (88 points): n100n \le 100;
  • (99 points): n2000n \le 2000;
  • (1313 points): n5000n \le 5000;
  • (2828 points): n105n \le 10^5;
  • (2323 points): with no additional restrictions.