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 ...
随机推荐
- SpringBoot接口服务处理Whitelabel Error Page
转载请注明来源:http://blog.csdn.net/loongshawn/article/details/50915979 <SpringBoot接口服务处理Whitelabel Erro ...
- CXAnimation.h动画类
/**************************************************************************** 使用一个CCAnimation对象可以CCS ...
- makefile之include
"include"指示符告诉 make 暂停读取当前的 Makefile,而转去读取"include"指定的一个或者多个文件,完成以后再继续当前 Makefil ...
- SCWS 中文分词
SCWS 中文分词v1.2.3 开源免费的中文分词系统,PHP分词的上乘之选! 首页 下载 演示 文档 关于 服务&支持 API/HTTP 论坛 捐赠 源码@github 文档目录 SCWS- ...
- java中高并发和高响应解决方法
并发不高.任务执行时间长的业务要区分开看: 假如是业务时间长集中在I/O操作上,也就是I/O密集型的任务,因为I/O操作并不占用CPU,所以不要让所有的CPU闲下来,可以加大线程池中的线程数目,让CP ...
- Python操作Word:常用对象介绍
前面已经介绍过了试用win32com类库来进行Word开发,系列文章<Python操作Word>是继承了前面的文章,所以,你应该先查看前面的文章,其实只有两篇,文章地址列在最下面的参考资料 ...
- windows下安装配置apacheserver
注:一開始公布的时候 图片是复制粘贴的.所以公布完图片所有消失了...如今是补发图片. . .2016/04/25 1.进入apache官网 http://httpd.apache.org/ 这里我 ...
- ReentrantReadWriteLock读写锁的使用<转>
Lock比传统线程模型中的synchronized方式更加面向对象,与生活中的锁类似,锁本身也应该是一个对象.两个线程执行的代码片段要实现同步互斥的效果,它们必须用同一个Lock对象. 读写锁:分为读 ...
- Spider Studio 新版本 (20140225) - 设置菜单调整 / 提供JQueryContext布局相关的方法
这是年后的第一个新版本, 包含如下: 1. 先前去掉的浏览器设置功能又回来了! 说来惭愧, 去掉了这两个功能之后发现浏览经常会被JS错误打断, 很不方便, 于是乎又把它们给找回来了. :) 2. 为J ...
- go hmac使用
https://github.com/danharper/hmac-examples 94 func generateSign(data, key []byte) string { 95 mac := ...