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. 解题报告(一)D、(CROC 2016 - Final Round C)Binary Table(矩阵 + 状态压缩 + FWT)(3.5)

    繁凡出品的全新系列:解题报告系列 -- 超高质量算法题单,配套我写的超高质量题解和代码,题目难度不一定按照题号排序,我会在每道题后面加上题目难度指数(1∼51 \sim 51∼5),以模板题难度 11 ...

  2. 8VC Venture Cup 2016 - Final Round (Div. 2 Edition) C. XOR Equation 数学

    C. XOR Equation 题目连接: http://www.codeforces.com/contest/635/problem/C Description Two positive integ ...

  3. CROC-MBTU 2012, Elimination Round (ACM-ICPC) 总结

    A. System Administrator 模拟:直接计算同类第一项相加是否大于等于总和的一半 B. Internet Address 字符串:关键在于找"ru" C. Gam ...

  4. Technocup 2020 - Elimination Round 2 E. Rock Is Push dp

    传送门 文章目录 题意: 思路 题意: 给你一个n×mn×mn×m的方格,你初始在(1,1)(1,1)(1,1)点,有些位置有箱子,你可以走到某个位置向你的方向推动这个箱子,箱子不能出界,问你走到(n ...

  5. COCI 2016/2017 Round #3 题解

    COCI 2016/2017 Round #3 这套题代码量似乎有些大呀...前五题代码都已经破4KB了... 而且还要卡空间.卡常数... Imena 题目翻译 分析 细节模拟题,注意可能会出现名字 ...

  6. COCI 2016/2017 Round #5题解

    COCI 2016/2017 Round #5 Tuna 题目翻译 分析 水题,按题意模拟即可. 参考代码 #include<cstdio> #include<algorithm&g ...

  7. Croc Champ 2013 - Round 2 (Div. 2 Edition) 贪心+ 搜索+剪枝 + 数学

    A: 直接找出最小值,看是否能被所有数整除即可 B: 判断是否出现连续的"#">=m若果存在肯定不能调. C: 题意: 两个人玩游戏(A,B),每个人分配一个字符串长度为2* ...

  8. Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) B. Verse Pattern 水题

    B. Verse Pattern 题目连接: http://codeforces.com/contest/722/problem/B Description You are given a text ...

  9. szu cf套题训练Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3)A~D题解报告

    A. Math Problem 题目大意:就是给你n个线段,你自己再添加一个线段d使得d和所有的线段都有交点,求d这个线段的最小长度是多少 解题思路: 1.首先看d线段的左端点,就是左端点选取的是所有 ...

最新文章

  1. 区块链最积极的布局者:国内5大银行已将“区块链”应用到5大场景当中
  2. 路由表查找算法概述-哈希/LC-Trie树/256-way-mtrie树
  3. Spring对事务管理的支持的发展历程--转
  4. Python(2)-- 运算符
  5. mybatis02--增删改查
  6. 软件设计模式—依赖注入
  7. C语言——数组、函数、指针
  8. 【Python实战】使用python批量生成发票
  9. Python IDLE 快捷键
  10. matplotlib之scatter
  11. 如何在Azure Data Studio中导出数据库?
  12. git push或git pull等其他git命令 出现unable to access ‘https://gitee.com/你的git仓库地址)清除网络代理
  13. js中进行字符串替换的方法
  14. [转]用python来开发webgame服务端(3)
  15. [转载]分布式双活数据中心
  16. canvas教程2-canvas的编程思想
  17. PowerBuilder常用函数
  18. CE是什么缩写,是什么含义
  19. python实战演练_《Python高效开发实战》实战演练——基本视图3
  20. Vmware安装OpenWrt

热门文章

  1. PHP内容管理系统新项目,EyeOS - 内容管理CMS - PHP开源项目 - 开源吧
  2. httpClinent短信验证码
  3. Synergy配置过程--实现跨电脑的键鼠互通操作
  4. Mac和Deepin共享键盘鼠标Synergy
  5. 进销存管理软件2021下载量最多的排行榜前五名
  6. 【愚公系列】2023年01月 Java教学课程 003-Hello World的运行
  7. “系统资源不足,无法满足请求服务“ ,而内存够大,解决办法
  8. Sharepoint 2010:备份与恢复
  9. 海伦公C语言表达式,一道简单的C语言海伦公式问题
  10. [分享]PHP多城市版-房产系统源码,仿贝壳房产。