645B.md (1943B)
1 Source: https://codeforces.com/problemset/problem/645/B 2 3 B. Mischievous Mess Makers 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 It is a balmy spring afternoon, and Farmer John's *n* cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through *n*, are arranged so that the *i*-th cow occupies the *i*-th stall from the left. However, Elsie, after realizing that she will forever live in the shadows beyond Bessie's limelight, has formed the Mischievous Mess Makers and is plotting to disrupt this beautiful pastoral rhythm. While Farmer John takes his *k* minute long nap, Elsie and the Mess Makers plan to repeatedly choose two distinct stalls and swap the cows occupying those stalls, making no more than one swap each minute. 22 23 Being the meticulous pranksters that they are, the Mischievous Mess Makers would like to know the maximum messiness attainable in the *k* minutes that they have. We denote as *p**i* the label of the cow in the *i*-th stall. The messiness of an arrangement of cows is defined as the number of pairs (*i*, *j*) such that *i* < *j* and *p**i* > *p**j*. 24 25 Input 26 27 The first line of the input contains two integers *n* and *k* (1 ≤ *n*, *k* ≤ 100 000) — the number of cows and the length of Farmer John's nap, respectively. 28 29 Output 30 31 Output a single integer, the maximum messiness that the Mischievous Mess Makers can achieve by performing no more than *k* swaps. 32 33 Examples 34 35 Input 36 37 ``` 38 5 2 39 ``` 40 41 Output 42 43 ``` 44 10 45 ``` 46 47 Input 48 49 ``` 50 1 10 51 ``` 52 53 Output 54 55 ``` 56 0 57 ``` 58 59 Note 60 61 In the first sample, the Mischievous Mess Makers can swap the cows in the stalls 1 and 5 during the first minute, then the cows in stalls 2 and 4 during the second minute. This reverses the arrangement of cows, giving us a total messiness of 10. 62 63 In the second sample, there is only one cow, so the maximum possible messiness is 0.