Circle of Mistery
题号:NC256219
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Ran is good at solving graph problems, but this time she has a great trouble because the problem Yukari gives her is too hard! Ran needs your help!

So here's the Circle of Mistery Problem:

Give an integer array w of length n and an integer k. Ran needs to construct a permutaion p. Let's use p to construct a graph: connect i and p_i together. Obviously, the graph will contain several circles. Ran has to make sure at least one circle a_1\to a_2\to\dots\to a_x\to a_1 (x\ge1) satisfy that \sum_{i=1}^x w_{a_i}\ge k. That means, circle a_1\to a_1 is legal.

Try to find the permutation p with the minimum number of inversions and output the number. An inversion in an array a is a pair of indices (i, j) such that i > j and a_i < a_j.

输入描述:

The first line contains two integers n (1\le n\le 10^3) and k (-10^6\le k\le10^6).
The next line contains n integers, the i-th one means w_i (-10^6\le w_i\le 10^6).

输出描述:

If it's impossible to construct p, output -1. Otherwise output the minimum number of inversions in p.
示例1

输入

复制
3 3
2 2 1

输出

复制
1
示例2

输入

复制
5 3
-3 2 -1 0 2

输出

复制
3
示例3

输入

复制
2 -3
-5 -5

输出

复制
-1

备注:

For the second sample, p=\{1,5,2,3,4\}. The circle 2\to5\to4\to3\to2 satisfies the condition.