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 ...
随机推荐
- CSectsInfomation.h文件
#ifndef SECTSINFOMATION_H #define SECTSINFOMATION_H #include "XWidget.h" #include "XI ...
- 动态修改 dom 元素的伪类样式
最近写代码,需要修改伪类的 content 属性,不想定义两个样式进行切换,而是直接通过 js 进行修改. html 中的伪类(如 a:hover / a:link / class::before / ...
- 深入剖析 linux GCC 4.4 的 STL string
转自: 深入剖析 linux GCC 4.4 的 STL string 本文通过研究STL源码来剖析C++中标准模板块库std::string运行机理,重点研究了其中的引用计数和Copy-On-Wri ...
- django中ModelForm save方法 以及快速生成空表单或包含数据的表单 包含错误信息
django中ModelForm学习系列一~save方法 Model代码 from django.db import models # Create your models here. class P ...
- linux超级终端minicom的使用方法
===== 一.Minicom介绍 ===== Linux下的Minicom的功能与Windows下的超级终端功能相似,可以通过串口控制外部的硬件 设备.适于在linux通过超级终端对 ...
- 高德地图API INVALID_USER_SCODE问题以及keystore问题
今天这篇文章会给大家介绍三个问题: 1,接入API时出现invalid_user_scode问题 首先进行第一个大问题,接入高德地图API时出现invalid_user_scode问题 因为项目需要接 ...
- python模块:xlsxwriter和xlrd相结合读取
python模块简单说明: xlsxwriter:负责写入数据 xlrd:负责读取数据 xlsxwriter 官方文档:http://xlsxwriter.readthedocs.org 本实例是刚写 ...
- STM32F1_常见外设资源汇总
前言 STM32F1系列芯片算是在STM32中最早的一系列,在实际生活中应用的比较广泛.因此,汇总一下STM32F1系列芯片常见片内资源,每一篇文章把重点提出来讲解,并提供软件源代码工程. 汇总常见资 ...
- centos6.5 系统上升级2.6.6到2.7.12
因开发需要,今天把CentOS 6.4自带的Python2.6.6升级到了Python2.7.3.按照如下步骤进行升级 1.查看当前系统python的版本 python -V 2.下载2.7.3版本的 ...
- TensorFlow基础笔记(1) 数据读取与保存
https://zhuanlan.zhihu.com/p/27238630 WholeFileReader # 我们用一个具体的例子感受tensorflow中的数据读取.如图, # 假设我们在当前文件 ...