问题 B: Circle of Mistery

内存限制:128 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:0 通过:0

题目描述

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 www of length nnn and an integer kkk. Ran needs to construct a permutaion ppp. Let's use ppp to construct a graph: connect iii and pip_ipi together. Obviously, the graph will contain several circles. Ran has to make sure at least one circle a1→a2→⋯→ax→a1a_1\to a_2\to\dots\to a_x\to a_1a1a2axa1 (x≥1x\ge1x1) satisfy that ∑i=1xwai≥k\sum_{i=1}^x w_{a_i}\ge ki=1xwaik. That means, circle a1→a1a_1\to a_1a1a1 is legal.

Try to find the permutation ppp with the minimum number of inversions and output the number. An inversion in an array aaa is a pair of indices (i,j)(i, j)(i,j) such that i>ji > ji>j and ai<aja_i < a_jai<aj.

输入格式

The first line contains two integers nnn (1≤n≤1031\le n\le 10^31n103) and kkk (−106≤k≤106-10^6\le k\le10^6106k106).
The next line contains nnn integers, the iii-th one means wiw_iwi (−106≤wi≤106-10^6\le w_i\le 10^6106wi106).

输出格式

If it's impossible to construct ppp, output −1-11. Otherwise output the minimum number of inversions in ppp.

输入样例 复制

3 3
2 2 1

输出样例 复制

1