No.1341 Swap the Middles to Make Kadomatsu Sequences
タグ : / 解いたユーザー数 25
作問者 :
nmnmnmnmnmnmnm
/ テスター :
37zigen
Problem Statement
A Kadomatsu sequence is defined as follows: when three integers are arranged as $A$, $B$, $C$ from the left,
all the values are distinct and the second largest integer among $A$, $B$, $C$ is either $A$ or $C$.
Also, when three integers form a Kadomatsu sequence, their Kadomatsu points are the maximum value among the three integers.
You are given $N$ triples of three positive integers $A$, $B$, $C$, in this order from the left.
You may perform, up to $N$ times, an operation that swaps only the middle positive integers $B$ between any two triples.
Determine whether all the triples can be made into Kadomatsu sequences by the operations.
If they can, determine whether the sum of the Kadomatsu points of all the triples can be made at least $M$ points.
Input
$N$ $M$ $A_1$ $B_1$ $C_1$ $A_2$ $B_2$ $C_2$ $ \vdots\ $ $A_N$ $B_N$ $C_N$
$N$ is the number of given triples of three positive integers $A$, $B$, $C$. $1 \le N \le 3000$.
$M$ is the number of points used for the determination in the problem statement. $0 \le M \le 3000000000000 = 3 \times 10^{12}$.
$A_i$, $B_i$, $C_i$ are the positive integers $A$, $B$, $C$ of the $i$-th given triple. $A_i \neq C_i$. $1 \le A_i,B_i,C_i \le 1000000000 = 10^9$.
Output
If not all the triples can be made into Kadomatsu sequences, output "NO" on a single line only.
If all the triples can be made into Kadomatsu sequences, output "YES" on the first line.
If all the triples can be made into Kadomatsu sequences and the sum of the Kadomatsu points can be made at least $M$ points, output "KADOMATSU!" on the second line.
If all the triples can be made into Kadomatsu sequences but the sum of the Kadomatsu points cannot be made at least $M$ points, output "NO" on the second line.
Sample
Sample 1
Input
2 5 2 3 4 1 1 2
Output
YES KADOMATSU!
Swap the middle number 3 of the first triple with the middle number 1 of the second triple.
With this single swap, both triples become Kadomatsu sequences, so output "YES".
The Kadomatsu points of the first triple are 4, the maximum of "2,1,4".
The Kadomatsu points of the second triple are 3, the maximum of "1,3,2".
Therefore, the sum of the Kadomatsu points is 4+3=7 points.
This is at least the threshold of 5 points, so output "KADOMATSU!".
Sample 2
Input
3 20 7 5 5 2 8 1 4 3 5
Output
YES KADOMATSU!
This can be done with 2 operations.
Sample 3
Input
1 100 2 1 3
Output
YES NO
The triple is a Kadomatsu sequence from the start, so all the triples can be made Kadomatsu sequences with 0 operations.
However, the sum of the Kadomatsu points cannot be made at least the threshold.
Sample 4
Input
2 0 1 2 3 4 1 3
Output
NO
Not all the triples can be made into Kadomatsu sequences.
Sample 5
Input
5 2021 5 10 1 3 3 16 7 8 8 11 1979 15 6 8 9
Output
YES KADOMATSU!
Happy New Year 2021!
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。