Code Forces 645B Mischievous Mess Makers
来源:互联网 发布:淘宝上解id锁是真的吗 编辑:程序博客网 时间:2024/04/30 02:54
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
- Codeforces 645B Mischievous Mess Makers 【逆序对】
- Codeforces 645B Mischievous Mess Makers【逆序数】
- CodeForces 645 B.Mischievous Mess Makers(水~)
- 题解:Mischievous Mess Makers
- (CROC 2016 - Elimination Round (Rated Unofficial Edition))B. Mischievous Mess Makers(贪心)
- 【CROC 2016 - Elimination RoundB】【贪心】Mischievous Mess Makers 全排列1到n交换k次最多逆序数
- Code forces 699B
- code forces 404B Marathon
- code forces 408B Garland
- Code Forces 242 B. Big Segment 贪心
- Code Forces 271B 预处理+预处理
- code forces 393B Three matrices
- code forces 394B Very Beautiful Number
- code forces 399B Red&Blue Balls
- code forces 401B Sereja and Contests
- code forces 405B Domino Effect
- HDU-1501 (POJ-2192) Zipper (DFS||DP)
- 下拉列表框Spinner
- [疯狂Java]JDBC:用blob处理多媒体类型数据
- Codeforces 345 div1
- IosApp开发简单实例
- Code Forces 645B Mischievous Mess Makers
- 使用maven自动打包android应用签名后报错:INSTALL_PARSE_FAILED_NO_CERTIFICATES
- mysql 5.6.20的安装、配置服务、设置编码格式
- 文件操作
- 公司一小伙圆识别
- [LintCode] 二叉树的层序遍历 Binary Tree Level Order Tranversal
- 1017
- 【卡特兰数+高精度】HDU1023Train Problem II
- SpringMVC的几种返回方式