B. Mischievous Mess Makers

题目连接:

http://www.codeforces.com/contest/655/problem/B

Description

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.

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 pi 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 pi > pj.

Input

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.

Output

Output a single integer, the maximum messiness that the Mischievous Mess Makers can achieve by performing no more than k swaps.

Sample Input

5 2

Sample Output

10

Hint

题意

给你1到n的序列,然后你可以最多交换k次

让你使得逆序数最多,问你答案是多少

题解:

贪心,第一个数和最后一个数交换,第二个数和倒数第二个数交换,然后这样就好了

每次对答案的贡献是2*(n-i-i)+1

这个画画图就知道了。

代码

#include<bits/stdc++.h>
using namespace std; long long ans,n,k;
int main()
{
cin>>n>>k;
for(int i=1;i+i<=n&&i<=k;i++)
ans+=2*(n-i-i)+1;
cout<<ans<<endl;
}

CROC 2016 - Elimination Round (Rated Unofficial Edition) B. Mischievous Mess Makers 贪心的更多相关文章

  1. CROC 2016 - Elimination Round (Rated Unofficial Edition) D. Robot Rapping Results Report 二分+拓扑排序

    D. Robot Rapping Results Report 题目连接: http://www.codeforces.com/contest/655/problem/D Description Wh ...

  2. CROC 2016 - Elimination Round (Rated Unofficial Edition) D. Robot Rapping Results Report 拓扑排序+二分

    题目链接: http://www.codeforces.com/contest/655/problem/D 题意: 题目是要求前k个场次就能确定唯一的拓扑序,求满足条件的最小k. 题解: 二分k的取值 ...

  3. CROC 2016 - Elimination Round (Rated Unofficial Edition) F - Cowslip Collections 数论 + 容斥

    F - Cowslip Collections http://codeforces.com/blog/entry/43868 这个题解讲的很好... #include<bits/stdc++.h ...

  4. CROC 2016 - Elimination Round (Rated Unofficial Edition) E - Intellectual Inquiry dp

    E - Intellectual Inquiry 思路:我自己YY了一个算本质不同子序列的方法, 发现和网上都不一样. 我们从每个点出发向其后面第一个a, b, c, d ...连一条边,那么总的不同 ...

  5. CROC 2016 - Elimination Round (Rated Unofficial Edition) E. Intellectual Inquiry 贪心 构造 dp

    E. Intellectual Inquiry 题目连接: http://www.codeforces.com/contest/655/problem/E Description After gett ...

  6. CROC 2016 - Elimination Round (Rated Unofficial Edition) C. Enduring Exodus 二分

    C. Enduring Exodus 题目连接: http://www.codeforces.com/contest/655/problem/C Description In an attempt t ...

  7. CROC 2016 - Elimination Round (Rated Unofficial Edition) A. Amity Assessment 水题

    A. Amity Assessment 题目连接: http://www.codeforces.com/contest/655/problem/A Description Bessie the cow ...

  8. CF #CROC 2016 - Elimination Round D. Robot Rapping Results Report 二分+拓扑排序

    题目链接:http://codeforces.com/contest/655/problem/D 大意是给若干对偏序,问最少需要前多少对关系,可以确定所有的大小关系. 解法是二分答案,利用拓扑排序看是 ...

  9. 8VC Venture Cup 2016 - Elimination Round D. Jerry's Protest 暴力

    D. Jerry's Protest 题目连接: http://www.codeforces.com/contest/626/problem/D Description Andrew and Jerr ...

随机推荐

  1. S3C6410 SPI全双工读写流程分析(原创)【转】

    转自:http://blog.csdn.net/hustyangju/article/details/21165721 原创博文,知识共享!转载请注明出处:http://blog.csdn.net/h ...

  2. nginx location 指令意义

    基本语法:location [=|~|~*|^~] /uri/ { … } = 严格匹配.如果这个查询匹配,那么将停止搜索并立即处理此请求.~ 为区分大小写匹配(可用正则表达式)!~为区分大小写不匹配 ...

  3. C/C++——[05] 函数

    函数是 C/C++语言中的一种程序组件单位.一个函数通常代表了一种数据处理的功能,由函数体和函数原型两部分组成.函数原型为这个数据处理功能指定一个标识符号(函数的名称).说明被处理数据的组成及其类型. ...

  4. RSA加密登录

    1.首先下载前端JS加密框架:jsencrypt 2.后台添加解密帮助类:RSACrypto(参考文章最后) 3.在登录页面先引入jquery.min.js,在引入jsencrypt.min.js 4 ...

  5. EnumSet基本用法

    enum Season { SPRING, SUMMER, FALL, WINTER } public class EnumSetTest { public static void main(Stri ...

  6. python实现IMAP协议下email收取

    本文为转载,原文在这里. 所谓无痕取信,目前主要是指从邮箱中把信件收取后,邮箱内状态不发生任何改变.这里的状态主要是指两部分,一部分是邮件状态不变,即已读与未读状态不变,另一部分是指邮箱记录的登陆IP ...

  7. java 获取路径的各种方法

    (1).request.getRealPath("/");//不推荐使用获取工程的根路径 (2).request.getRealPath(request.getRequestURI ...

  8. Typo: In word 拼写检查

    Settings->Inspections > Spelling > Typo 评写检查,

  9. scrollview和viewpager滑动冲突

    import android.content.Context; import android.util.AttributeSet; import android.view.MotionEvent; i ...

  10. ApplicationContext中getBean详解

    在org.springframework.context包中有一个接口叫 applicationContext applicationContext中有一个getBean方法,此方法继承之BeanFa ...