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. linux 查看内存和cpu占用比较多的进程

    1.可以使用一下命令查使用内存最多的10个进程        ps -aux | sort -k4nr | head -n 102. 可以使用一下命令查使用CPU最多的10个进程        ps ...

  2. 初识PDO数据库抽象层

    目录: 00x1 php中的pdo是什么? 00x2 pdo创建一个PDO对象 00x1 php中的pdo是什么? 就是操作数据库的方法,pdo就是把操作数据库的函数封装成一个pdo类,其间做了安全验 ...

  3. ubuntu之安装pycharm编辑器

    pycharm是Java写的,运行需要Java环境. 安装java jdk sudo add-apt-repository ppa:webupd8team/java sudo apt-get upda ...

  4. svn add --no-ignore

    提交新代码时:svn add --no-ignore  /dir   不加的话可能会漏提交某些依赖或文件. Svn st -q --no-ignore. 提交时不需要加

  5. 去除\ufeff的解决方法,python语言

    语言:python 编程工具:pycharm 硬件环境:win10 64位 读取文件过程中发现一个问题:已有记事本文件(非空),转码 UTF-8,复制到pycharm中,在开始位置打印结果会出现  \ ...

  6. Python 库汇总中文版

    这又是一个 Awesome XXX 系列的资源整理,由 vinta 发起和维护.内容包括:Web框架.网络爬虫.网络内容提取.模板引擎.数据库.数据可视化.图片处理.文本处理.自然语言处理.机器学习. ...

  7. php强制输出到浏览器下载

    $file_name="test.mp3"; $mp3_url = "";header( "Pragma: public" );header ...

  8. XSS与CSRF两种跨站攻击总结

    在那个年代,大家一般用拼接字符串的方式来构造动态 SQL 语句创建应用,于是 SQL 注入成了很流行的攻击方式.在这个年代, 参数化查询 [1] 已经成了普遍用法,我们已经离 SQL 注入很远了.但是 ...

  9. vs 单元测试

    vs 2010 NOget 包 安装NUnitTDNet,下载TestDriven.NET(http://www.testdriven.net/). 准备动作 先到http://www.testdri ...

  10. 在 Windows 上进行 Laravel Homestead 安装、配置及测试

    软件环境:在 Windows 7 64位 上基于 VirtualBox 5.2.12 + Vagrant 2.1.1 使用 Laravel Homestead. 1.准备 先下载VirtualBox- ...