아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Remix

시간 제한2초메모리 제한1024 MB

요약
현재 multiset에서 부분집합을 골라 최댓값과 최솟값의 차로 바꾸는 연산을 반복해 마지막에 남는 정수를 최대로 만든다.
난이도

보통10점 중 7점

유형
그리디, 정렬, 수학
정답자
아직 제출이 없습니다

문제

You are given a multiset ss consisting of nn integers. You should perform the following three-step operation some number of times until a single integer remains in ss.

  • Choose a multiset tt such that t⊆st \subseteq s and ∣t∣≥2|t| \ge 2.
  • Erase the elements of tt from ss.
  • Insert max⁡(t)−min⁡(t)\max(t) - \min(t) to ss.

Find a sequence of operations that maximizes the integer left in ss.

입력

The first line contains a single integer nn (2≤n≤105)(2 \le n \le 10^5).

The second line contains nn integers s_1,s_2,…,s_ns\_1, s\_2, \ldots, s\_n (0≤s_i≤105)(0 \le s\_i \le 10^5).

출력

On the first line, print a single integer kk (1≤k≤n−1)(1 \le k \le n-1), the number of operations.

On each of the next kk lines, print an integer mm (2≤m≤n)(2 \le m \le n), the size of the chosen multiset tt, followed by mm integers, t_1,t_2,…,t_mt\_1, t\_2, \ldots, t\_m.

Note that the operations are executed in the same order they are listed. So, for each operation, tt must be a subset of ss when all the preceding operations are performed.

힌트

The sample does the following operations:

 Chosen ttNew ss
00 24,33,48,63,90,93,97\\{24, 33, 48, 63, 90, 93, 97\\}
1133,90,93\\{33, 90, 93\\}24,48,60‾,63,97\\{24, 48, \underline{60}, 63, 97\\}
2260,63\\{60, 63\\}3‾,24,48,97\\{\underline{3}, 24, 48, 97\\}
3324,48\\{24, 48\\}3,24‾,97\\{3, \underline{24}, 97\\}
443,24,97\\{3, 24, 97\\}94‾\\{\underline{94}\\}

The values underlined in ss denote the integer inserted. After the fourth operation, ss is reduced to a single integer value of 9494. It can be shown that no other sequence of operations results in a larger value.

예제1

  1. 예제 1

    입력
    7
    33 24 63 48 97 90 93
    
    예상 출력
    4
    3 33 93 90
    2 63 60
    2 48 24
    3 97 24 3