传送门

首先对于两个排列 $A,B$ 我们可以把 $A$ 从小到大排序并把 $B$ 重新和 $A$ 一一对应

显然这样不会影响 $\sum_{i=1}^{n}max(A_i,B_i)$ 的值

所以直接把第一个排列固定为 $1,2,3,...,n$

然后考虑第二个排列 $B$ 怎么排比较好

首先最少的时间一定就是 $B_i=i$ 的情况

然后考虑让时间变大,容易想到把 $B_1$ 和 $B_n$ 交换,变成 $n,2,3,...,n-1,1$

那么时间增加了 $n-1$,一直操作最后 $B$ 就变成 $n,n-1,n-2,...,3,2,1$

那么容易想到贪心,每次都先加得比较大,最后快超过的时候再加一个比较小的

容易证明这个显然是最优的,因为一开始就加大的之后的选择就有更多空间(有更多比较小的值可以增加)

不然到时候还剩下一些时间,发现增加的量都很大那么就没法加了

(可能看代码更容易理解?)

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline ll read()
{
ll x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
const int N=1e6+;
int n,ans[N];
ll m;
int main()
{
n=read(),m=read(); ll mx=m;
for(int i=;i<=n;i++)
ans[i]=i,m-=i;
if(m<) { printf("-1\n"); return ; }
for(int i=;i<=n/;i++)
{
int now=(n-i+)-i;
if(m<=now)
{
swap( ans[ n-i+ - (now-m) ] , ans[i] );
// 显然 n-i-1 - (now-m) > i,代入一下 now=n-2i+1 即可
m=; break;
}
swap(ans[n-i+],ans[i]); m-=now;
}
printf("%lld\n",mx-m);
for(int i=;i<=n;i++) printf("%d ",i); puts("");
for(int i=;i<=n;i++) printf("%d ",ans[i]); puts("");
return ;
}

Codeforces 1244G. Running in Pairs的更多相关文章

  1. codeforces 652C C. Foe Pairs(尺取法+线段树查询一个区间覆盖线段)

    题目链接: C. Foe Pairs time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  2. CodeForces - 9B - Running Student

    先上题目: B. Running Student time limit per test 1 second memory limit per test 64 megabytes   And again ...

  3. CodeForces - 1189 E.Count Pairs (数学)

    You are given a prime number pp, nn integers a1,a2,…,ana1,a2,…,an, and an integer kk. Find the numbe ...

  4. Codeforces 1404D - Game of Pairs(构造)

    Codeforces 题面传送门 & 洛谷题面传送门 首先注意到 \(\sum\limits_{i=1}^{2n}i=\dfrac{2n(2n+1)}{2}=n(2n+1)\equiv n\p ...

  5. Codeforces 1542E2 - Abnormal Permutation Pairs (hard version)(DP)

    upd on 2021.7.7:修了个 typo Codeforces 题目传送门 & 洛谷题目传送门 首先考虑怎样处理"字典序小"这个问题,按照字典序比大小的套路,我们可 ...

  6. Codeforces 615C Running Track(DP + Trie树)

    题目大概说给两个串,问最少要用多少个第一个串的子串(可以翻转)拼成第二个串. UVa1401,一个道理..dp[i]表示前缀i拼接成功所需最少的子串,利用第一个串所有子串建立的Trie树往前枚举转移. ...

  7. Codeforces Round #338 (Div. 2) C. Running Track dp

    C. Running Track 题目连接: http://www.codeforces.com/contest/615/problem/C Description A boy named Ayrat ...

  8. Codeforces Beta Round #9 (Div. 2 Only) B. Running Student 水题

    B. Running Student 题目连接: http://www.codeforces.com/contest/9/problem/B Description And again a misfo ...

  9. Educational Codeforces Round 10 C. Foe Pairs 水题

    C. Foe Pairs 题目连接: http://www.codeforces.com/contest/652/problem/C Description You are given a permu ...

随机推荐

  1. weight权重的属性

    权重是把屏幕剩余空间按比例分配 控件使用0dp,则实际的宽度比就等于权重比 控件wrap_content,那么权重越大,位置占的越多,再小不过wrap_content 控件match_parent,那 ...

  2. Python3+RobotFramewok 用户自定义库的开发(四)

    在介绍这个之前,可以先看下python的目录Python\Lib\site-packages下面的文件夹,你会发现这个目录下面有DatabaseLibrary.RequestsLibrary.Sele ...

  3. PCL中有哪些可用的PointT类型(4)

    博客转载自:http://www.pclcn.org/study/shownews.php?lang=cn&id=269 PointWithViewpoint - float x, y, z, ...

  4. 小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_5-5.HttpClient4.x工具获取使用

    笔记 5.HttpClient4.x工具获取使用     简介:讲解httpClient4.x相关依赖,并封装基本方法. 1.加入依赖         <dependency>       ...

  5. vue 组件属性props,特性驼峰命名,连接线使用

    网址:https://www.cnblogs.com/alasq/p/6363160.html 总结如下:vue的组件的props属性支持驼峰命名,不支持连接线命名,使用是用连接线进行赋值或者数据绑定 ...

  6. Java相关框架概念以及思想

    1.什么是IoC Ioc—Inversion of Control,即“控制反转”,是一种思想, 一个重要的面向对象编程的法则,它能指导我们如何设计出松耦合.更优良的程序. 高内聚低耦合的设计能够让构 ...

  7. 一百二十八:CMS系统之轮播图的编辑和删除功能

    编辑 form,继承添加的form 视图 @bp.route('/ubanners/', methods=['POST'])@login_required@permission_required(CM ...

  8. 【Linux】部署NTP时间同步服务器

    1. 查看机器的Linux版本 查看集群内所有服务器的linux版本,确保相同,不要跨大版本. [root@bigdata111 ~]# cat /etc/redhat-release CentOS ...

  9. 使用Postman如何做接口自动化测试

    师从‘百测’! 一.简介 Postman是一款非常流行的API调试工具,很多攻城狮都应该用过,或听说过,这里不做过多介绍. 官方网站:http://www.getpostman.com 二.接口自动化 ...

  10. linux中查找命令find、locate、whereis、which、type的区别

    find find是最常见和最强大的查找命令,你可以用它找到任何你想找的文件.与查询数据库(/var/lib/locatedb)文件不同,find查找的是磁盘空间. locate locate命令其实 ...