#abc321b. B - Cutoff

B - Cutoff

Score : 200200 points

问题描述

一场考试的结构如下:

  • 考试包含 NN 轮,依次称为第 1 轮到第 NN 轮。
  • 在每一轮中,你会得到一个介于 00100100(包括两端点)之间的整数分数。
  • 你的最终成绩是除最高分和最低分以外,在各轮中获得的 N2N-2 个分数之和。
    • 格式上,令 S=(S1,S2,,SN)S=(S_1,S_2,\dots,S_N) 表示按升序排列的各轮所得分数序列,则最终成绩为 S2+S3++SN1S_2+S_3+\dots+S_{N-1}

现在,前 N1N-1 轮考试已经结束,你在第 ii 轮的得分为 AiA_i
请打印出在第 NN 轮中你必须至少获得多少分,才能使最终成绩达到或超过 XX 分。
若无论你在第 NN 轮中取得何种分数,最终成绩都无法达到或超过 XX 分,请打印 -1
注意:你在第 NN 轮中的分数只能是一个介于 00100100 之间的整数。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There is an exam structured as follows.

  • The exam consists of NN rounds called round 11 to NN.
  • In each round, you are given an integer score between 00 and 100100, inclusive.
  • Your final grade is the sum of the N2N-2 of the scores earned in the rounds excluding the highest and lowest.
    • Formally, let S=(S1,S2,,SN)S=(S_1,S_2,\dots,S_N) be the sequence of the scores earned in the rounds sorted in ascending order, then the final grade is S2+S3++SN1S_2+S_3+\dots+S_{N-1}.

Now, N1N-1 rounds of the exam have ended, and your score in round ii was AiA_i.
Print the minimum score you must earn in round NN for a final grade of XX or higher.
If your final grade will never be XX or higher no matter what score you earn in round NN, print -1 instead.
Note that your score in round NN can only be an integer between 00 and 100100.

Constraints

  • All input values are integers.
  • 3N1003 \le N \le 100
  • 0X100×(N2)0 \le X \le 100 \times (N-2)
  • 0Ai1000 \le A_i \le 100

Input

The input is given from Standard Input in the following format:

NN XX

A1A_1 A2A_2 \dots AN1A_{N-1}

Output

Print the answer.

Sample Input 1

5 180
40 60 80 50

Sample Output 1

70

Your scores in the first four rounds were 4040, 6060, 8080, and 5050.
If you earn a score of 7070 in round 55, the sequence of the scores sorted in ascending order will be S=(40,50,60,70,80)S=(40,50,60,70,80), for a final grade of 50+60+70=18050+60+70=180.
It can be shown that 7070 is the minimum score you must earn for a final grade of 180180 or higher.

Sample Input 2

3 100
100 100

Sample Output 2

0

Your scores in the first two rounds were 100100 and 100100.
If you earn a score of 00 in round 33, the sequence of the scores sorted in ascending order will be S=(0,100,100)S=(0,100,100), for a final grade of 100100.
Note that the highest score, 100100, is earned multiple times, and only one of them is excluded. (The same goes for the lowest score.)
It can be shown that 00 is the minimum score you must earn for a final grade of 100100 or higher.

Sample Input 3

5 200
0 0 99 99

Sample Output 3

-1

Your scores in the first four rounds were 00, 00, 9999, and 9999.
It can be shown that your final grade will never be 200200 or higher no matter what score you earn in round 55.

Sample Input 4

10 480
59 98 88 54 70 24 8 94 46

Sample Output 4

45

update @ 2024/3/10 01:40:13