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

Input

5 2

Output

10

Input

1 10

Output

0

#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <queue>
#include <map> using namespace std;
long long int n,k;
long long int ans;
int main()
{
scanf("%lld%lld",&n,&k);
long long int sum=(n*(n-1))/2;
int l=n;
ans=0;
if(n==1)
{
printf("0\n");
return 0;
}
for(int i=1;i<=k;i++)
{
ans+=(l-1+l-2);
l-=2;
if(ans==sum)
break;
}
printf("%lld\n",ans);
return 0;
}

Code Forces 645B Mischievous Mess Makers的更多相关文章

  1. CodeForces 645B Mischievous Mess Makers

    简单题. 第一次交换$1$和$n$,第二次交换$2$和$n-1$,第三次交换$3$和$n-2$.....计算一下就可以了. #pragma comment(linker, "/STACK:1 ...

  2. Codeforces 645B Mischievous Mess Makers【逆序数】

    题目链接: http://codeforces.com/problemset/problem/645/B 题意: 给定步数和排列,每步可以交换两个数,问最后逆序数最多是多少对? 分析: 看例子就能看出 ...

  3. CROC 2016 - Elimination Round (Rated Unofficial Edition) B. Mischievous Mess Makers 贪心

    B. Mischievous Mess Makers 题目连接: http://www.codeforces.com/contest/655/problem/B Description It is a ...

  4. codeforces 655B B. Mischievous Mess Makers(贪心)

    题目链接: B. Mischievous Mess Makers time limit per test 1 second memory limit per test 256 megabytes in ...

  5. Code Forces 645C Enduring Exodus

    C. Enduring Exodus time limit per test2 seconds memory limit per test256 megabytes inputstandard inp ...

  6. 思维题--code forces round# 551 div.2

    思维题--code forces round# 551 div.2 题目 D. Serval and Rooted Tree time limit per test 2 seconds memory ...

  7. Code Forces 796C Bank Hacking(贪心)

    Code Forces 796C Bank Hacking 题目大意 给一棵树,有\(n\)个点,\(n-1\)条边,现在让你决策出一个点作为起点,去掉这个点,然后这个点连接的所有点权值+=1,然后再 ...

  8. Code Forces 833 A The Meaningless Game(思维,数学)

    Code Forces 833 A The Meaningless Game 题目大意 有两个人玩游戏,每轮给出一个自然数k,赢得人乘k^2,输得人乘k,给出最后两个人的分数,问两个人能否达到这个分数 ...

  9. Code Forces 543A Writing Code

    题目描述 Programmers working on a large project have just received a task to write exactly mm lines of c ...

随机推荐

  1. 有关View的几个基础知识点-IOS开发

    转自:http://blog.csdn.net/iukey/article/details/7083165 我一般情况下不会使用interface builder去画界面,而是用纯代码去创建界面,不是 ...

  2. MongoDB随笔

    创建用户 db.createUser({user: "abc",pwd: "abc123",roles: [ { role: "readWrite&q ...

  3. C语言 面试

    P1(多选)有如下定义 int a; int *b; 则下列哪些语句是正确的:A: b=&a;B: b=*a;C: b=(int*)a;D: *b=a; 思路如下:b是一个int类型指针,a是 ...

  4. Windows Phone Unit Test 环境搭建

    单元测试对工程质量带来的作用就不详细说明了,本文只讨论如何在WP开发环境下搭建测试工程     历史 从WP7时代官方是不支持UnitTest工程的,因此需要采用WPToolkitTest这个工程来实 ...

  5. OpenERP 7 picking order 继承需要注意的地方

    stock.picking.out  和 stock.picking.in 都是继承自stock.picking 新添加columns时需要注意,在stock.picking.out和stock.pi ...

  6. php5共存php7

    PHP7与PHP5共存于CentOS7 原文参考 原理 思路很简单:PHP5是通过yum安装的在/usr/,套接字在/var/run/php-fpm.socket,PHP7自己编译装在/usr/loc ...

  7. 树莓派teamviewer远程 windows远程桌面

    https://mirror.tuna.tsinghua.edu.cn/help/raspbian/ 用这个源后,再安装 apt-get update https://download.teamvie ...

  8. ASP.NET MVC4 异常拦截

    ASP.NET MVC4 程序发生异常时,通过拦截Action的异常,重写ActionFilterAttribute 的方法OnActionExecuted实现. 具体实现代码如下: /// < ...

  9. 常用的easyui使用方法之二

    -------datagrid 1.获取某行的行号(row)tdg.datagrid('getRowIndex',rows)2.通过行号移除该行tdg.datagrid('deleteRow',ind ...

  10. 【BZOJ】1696: [Usaco2007 Feb]Building A New Barn新牛舍(贪心)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1696 原题要求min(sum{|x-xi|+|y-yi|}),且一定要看题:“没有两头牛的吃草位置是 ...