题目链接:

B. Mischievous Mess Makers

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 throughn, 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.

Examples
input
5 2
output
10
input
1 10
output
0
Note

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 stalls2 and 4 during the second minute. This reverses the arrangement of cows, giving us a total messiness of 10.

In the second sample, there is only one cow, so the maximum possible messiness is 0.

题意:问最多进行k此互换后,the number of pairs (i, j) such that i < j and pi > pj.

思路:由贪心可知,每次互换最外边的一对可以得到数目最大,每换一次最外边的一对,number增加2*n-3;

AC代码:

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

最新文章

  1. 了解Package Configurations
  2. 解决firefox和IE9对icon font字体的跨域访问问题
  3. 发发关于JavaScript的感慨,随手记几个js知识碎片
  4. POJ 3461 Oulipo(乌力波)
  5. Android5.0新控件CardView的介绍和使用
  6. OC6_代理的基本概念
  7. Java设计模式13:常用设计模式之桥接模式(结构型模式)
  8. 微软Hololens学院教程-Hologram 212-Voice(语音)【微软教程已经更新,本文是老版本】
  9. C++使用Json作为数据包装格式的通信
  10. java多线层同时运行的解决,同步代码块synchronized
  11. poj 3187 Backward Digit Sums(穷竭搜索dfs)
  12. CD key 生成
  13. Windows Phone开发(8):关于导航的小技巧
  14. 【webpack】-- 模块热替换
  15. jQuery总结--版本二 事件处理函数
  16. Linux Shell 下载网站指定文件
  17. 利用sdkman安装kotlin和java环境
  18. 使用镶嵌数据集 MosaicDataSet管理不同分辨率影像数据
  19. AssetBundle粒度与分配策略
  20. 将 Spring boot 项目打成可执行Jar包,及相关注意事项(main-class、缺少 xsd、重复打包依赖)

热门文章

  1. 【Atheros】minstrel速率调整算法源码走读
  2. SVN版本号控制软件-图片含义具体解释
  3. 2016 acm香港网络赛 C题. Classrooms(贪心)
  4. HDU 2588 GCD &amp;amp;&amp;amp; GCD问题总结
  5. java jdk和android sdk的安装以及环境变量的配置
  6. 使用weka训练一个分类器
  7. Python菜鸟之路:Python基础——函数
  8. Centos设置开机启动Apache和Mysql
  9. Python学习笔记_Python基础
  10. jauery table