Levels Tought:
Elementary,Middle School,High School,College,University,PHD
Teaching Since: | May 2017 |
Last Sign in: | 307 Weeks Ago, 6 Days Ago |
Questions Answered: | 66690 |
Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
Given an array of N integers A1, A2 ... AN and an integer K, count number of subarrays of A such that number of inversions in those subarrays is at least K.
Inversions in a subarray Ai, Ai+1 ... Aj is defined as number of pairs (a,b) such that i = a and Aa > Ab.
First line consists of N and K in single line. Next line contains N space separated integers denoting array A.
Â
Print the required answer in one line.
Should contain all the constraints on the input data that you may have. Format it like:
Â
Input 1: 4 1 1 2 4 0 Input 2: 2 0 1 2 Output 1: 3 Output 2: 3
Â
Let’s denote by A[i,j] the subarray Ai, Ai+1 ... Aj.
Example 1.
A[1,4], A[2,4], A[3,4] have at least 1 inversion.
Example 2.
All subarrays are valid.
Note: Large input files. Use scanf/printf instead of cin/coun
Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll