# Maximum Permutation Sum

## Problem

You are given an array $\ufffd$ of size $\ufffd$. The array will be used to perform $\ufffd$ queries, where each query is comprised of a pair of integers, denoted by ${\ufffd}_{\ufffd}$ and ${\ufffd}_{\ufffd}$.

Before the queries are executed, you are allowed to rearrange the elements in array $\ufffd$ as desired.

Next, an integer variable $\ufffd$ is initialized to 0. For each of the $\ufffd$-th queries, calculate the sum of elements from ${\ufffd}_{{\ufffd}_{\ufffd}}$ through ${\ufffd}_{{\ufffd}_{\ufffd}}$ inclusive (i.e. ${\ufffd}_{{\ufffd}_{\ufffd}}+{\ufffd}_{{\ufffd}_{\ufffd}+1}+\cdots +{\ufffd}_{{\ufffd}_{\ufffd}}$), and add this sum to $\ufffd$.

The objective of this problem is to find an arrangement of array $\ufffd$ that maximizes the final value of $\ufffd$ after all $\ufffd$ queries have been processed.

If there are multiple possible arrangements of $\ufffd$ which achieve this maximum value, you can output any.

### Input Format

- The first line of input will contain a single integer $\ufffd$, denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains two space-separated integers $\ufffd$ and $\ufffd$ — the length of array and number of queries, respectively.
- The next line contains $\ufffd$ space-separated integers denoting the elements of the array.
- The next $\ufffd$ lines describe the queries. The $\ufffd$-th of these $\ufffd$ lines contains two space-separated integers ${\ufffd}_{\ufffd}$ and ${\ufffd}_{\ufffd}$, describing the range for the $\ufffd$-th query.

### Output Format

For each test case, output on a new line the maximum possible value of $\ufffd$. And in the next line, output the rearranged array $\ufffd$, which achieves that maximum possible value.

### Constraints

- $1\le \ufffd\le 10000$
- $1\le \ufffd\le 200000$
- $1\le \ufffd\le 200000$
- $1\le {\ufffd}_{\ufffd}\le 100000$
- $1\le {\ufffd}_{\ufffd}\le {\ufffd}_{\ufffd}\le \ufffd$
- The sum of $\ufffd$ over all test cases won't exceed $2\cdot 1{0}^{5}$
- The sum of $\ufffd$ over all test cases won't exceed $2\cdot 1{0}^{5}$

The solution will be updated Soon :

## Chef ODD

## Problem

You want to partition the set $\ufffd=\{1,2,\dots ,\ufffd\}$ into $\ufffd$ sets ${\ufffd}_{1},{\ufffd}_{2},\dots ,{\ufffd}_{\ufffd}$, such that $\mathrm{\mid}{\ufffd}_{\ufffd}\mathrm{\mid}\ge 2$, and the sum of elements in each ${\ufffd}_{\ufffd}$ is odd.

Is it possible to do so?

Note 1: Partitioning the set $\ufffd=\{1,2,\dots ,\ufffd\}$ into $\ufffd$ sets ${\ufffd}_{1},{\ufffd}_{2},\dots ,{\ufffd}_{\ufffd}$ means that every element of $\ufffd$ should be in exactly one of the sets ${\ufffd}_{1},{\ufffd}_{2},\dots ,{\ufffd}_{\ufffd}$, and ${\ufffd}_{\ufffd}\subseteq \ufffd$, for all $1\le \ufffd\le \ufffd$.

Note 2: $\mathrm{\mid}\ufffd\mathrm{\mid}$ denotes the number of elements in the set $\ufffd$.

### Input Format

- The first line of input will contain a single integer $\ufffd$, denoting the number of test cases.
- The first line and only line of each test case contains two space-separated integers, $\ufffd$ and $\ufffd$.

## 0 Comments

If you have any doubts/suggestion/any query or want to improve this article, you can comment down below and let me know. Will reply to you soon.