Code Forces 645B Mischievous Mess Makers
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的更多相关文章
- CodeForces 645B Mischievous Mess Makers
简单题. 第一次交换$1$和$n$,第二次交换$2$和$n-1$,第三次交换$3$和$n-2$.....计算一下就可以了. #pragma comment(linker, "/STACK:1 ...
- Codeforces 645B Mischievous Mess Makers【逆序数】
题目链接: http://codeforces.com/problemset/problem/645/B 题意: 给定步数和排列,每步可以交换两个数,问最后逆序数最多是多少对? 分析: 看例子就能看出 ...
- 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 ...
- codeforces 655B B. Mischievous Mess Makers(贪心)
题目链接: B. Mischievous Mess Makers time limit per test 1 second memory limit per test 256 megabytes in ...
- Code Forces 645C Enduring Exodus
C. Enduring Exodus time limit per test2 seconds memory limit per test256 megabytes inputstandard inp ...
- 思维题--code forces round# 551 div.2
思维题--code forces round# 551 div.2 题目 D. Serval and Rooted Tree time limit per test 2 seconds memory ...
- Code Forces 796C Bank Hacking(贪心)
Code Forces 796C Bank Hacking 题目大意 给一棵树,有\(n\)个点,\(n-1\)条边,现在让你决策出一个点作为起点,去掉这个点,然后这个点连接的所有点权值+=1,然后再 ...
- Code Forces 833 A The Meaningless Game(思维,数学)
Code Forces 833 A The Meaningless Game 题目大意 有两个人玩游戏,每轮给出一个自然数k,赢得人乘k^2,输得人乘k,给出最后两个人的分数,问两个人能否达到这个分数 ...
- Code Forces 543A Writing Code
题目描述 Programmers working on a large project have just received a task to write exactly mm lines of c ...
随机推荐
- 安装配置PhoneGap开发环境(二)——使用Cordova取代PhoneGap创建项目
1 Cordova是谁 PhoneGap的官方文档说的非常清楚.Cordova是PhoneGap的引擎,这两者的关系类似于WebKit与Chrome浏览器的关系.所以一些核心的基础操作对于Cordov ...
- vue2.0实现图片加载失败默认显示图片
<div class="bg"> <img :src="goods.phoneFloorAd.resUrl" :onerror="e ...
- 一个很好用的系统管理的命令lsof(转载)
最近发现LOSF 命令在系统管理方面特别有用,把我搜集的资料总结如下 1.当在lsof后边没有跟任何参数时,该命令将会列出当前系统中被所有进程打开的所有文件#lsof|nl #nl命令打印出行号 2. ...
- Makefile 12——改善编译效率
从Makefile的角度看,一个可以改善编译效率的地方与其中的隐式规则有关.为了了解make的隐式规则,我们把之前的simple项目的Makefile做一点更改,删除生成.o文件的规则(与隐式规则相对 ...
- 商派onex本地部署无法进入的问题
商派最新版的ONex本地虚拟机部署项目无法进入注册的问题解决 进入项目的database.php文件,复制host的值 vim /etc/hosts,将hosts内容添加到/etc/hosts里面去就 ...
- 浅析StackTrace
我们在学习函数调用时,都知道每个函数都拥有自己的栈空间.一个函数被调用时,就创建一个新的栈空间.那么通过函数的嵌套调用最后就形成了一个函数调用堆栈.在c#中,使用StackTrace记录这个堆栈.你可 ...
- Unity3D 5.0版本+注册工具分享
Unity3D引擎5.0正式版本发布也有一段时间了.笔者今天下载了新版本顺便分享一下资源. 主要有两个资源,一个是5.0f4的官方客户端,另外一个是vs的调试插件.有需要的盆友就拿去.都在下面的连接地 ...
- sama5d3 环境检测 gpio--yk测试
说明: gpio的MAP关系 yk0--pioA7 yk1--pioA5 yk2--pioA9 yk3--pioA3 yk4--pioA1 yk5--pioA8 (端子从左--& ...
- 一次完整的https过程
参考: 1. 一次完整的HTTP事务是怎样一个过程? 2. The First Few Milliseconds of an HTTPS Connection 3. 也许,这样理解HTTPS更容易 4 ...
- 你真的需要一个jQuery插件吗
jQuery的插件提供了一个很好的方法,节省了时间和简化了开发,避免程序员从头开始编写每个组件.但是,插件也将一个不稳定因素引入代码中.一个好的插件节省了无数的开发时间,一个质量不好的插件会导致修复错 ...