CodeTON Round 4 (Div. 1 + Div. 2)C
C. Make It Permutation
我们希望尽可能少地进行操作可以使代价最小,我们如果要排列的话,那些重复的元素我们无论如何都要进行删除的,所以我们可以先把去重的代价计算出来,然后依次枚举排列的位数是多少,也就是枚举去重后的数组,其中的代价我们可以一次计算出来,当我们枚举第i个a时,前面1有 i - 1个数,而1~ai - 1所有数都需要有,所以一共需要补ai - i个数,而i后面所有数都需要删除需要删m - i个数,代价我们可以通过O(1)的时间复杂度计算出来,然后枚举i更新答案即可。
时间复杂度:O(n)
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
int c[N];
void run()
{
int n, a, b;
scanf("%d%d%d", &n, &a, &b);
LL val = 0, ans = 2e18;
set<int>s;
for(int i = 0; i < n; ++ i)
{
int x; scanf("%d", &x);
if(s.find(x) == s.end()) s.insert(x);
else val += a;
}
int m = 0;
for(auto it : s) c[++ m] = it;
for(int i = 1; i <= m; ++ i)
{
LL k = 1LL * (c[i] - i) * b + 1LL * (m - i) * a;
ans = min(k, ans);
}
ans = min(ans, 1LL * m * a + b);
printf("%lld\n", val + ans);
}
int main()
{
// freopen("1.in", "r", stdin);
int t;cin >> t;
while(t --) run();
return 0;
}
CodeTON Round 4 (Div. 1 + Div. 2)C的更多相关文章
- CF Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
1. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort 暴力枚举,水 1.题意:n*m的数组, ...
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...
- Codeforces Beta Round #27 (Codeforces format, Div. 2)
Codeforces Beta Round #27 (Codeforces format, Div. 2) http://codeforces.com/contest/27 A #include< ...
- Educational Codeforces Round 63 (Rated for Div. 2) 题解
Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...
- Educational Codeforces Round 39 (Rated for Div. 2) G
Educational Codeforces Round 39 (Rated for Div. 2) G 题意: 给一个序列\(a_i(1 <= a_i <= 10^{9}),2 < ...
随机推荐
- TrustZone——(一)
本文内容主要来源于网络,综合了网上的多篇文章,也加入了一些自己的理解,重新组织了文章结构使其便于理解. 主要参考的文章包括: 一篇了解TrustZone TrustZone领域先行者 TrustZon ...
- Django-4.2博客开发教程:需求分析并确定数据表(四)
前三步已经完成了一个初步流程,从创建项目>应用>数据迁移>访问首页.以下是我整理的基本流程,接下来一步一步完成整个项目. 1.我们的需求: 博客的功能主要分为:网站首页.文章分类.文 ...
- 2023ccpc大学生程序设计竞赛-wh
对于大一的我,只听说线下大型比赛,而第一次参加也必然心情激动,生为大一,由于没有参赛经历,所有不知道参赛技巧,所以三个人像个无头苍蝇一样,跟着榜单做,我作为写码的,其他两名队友负责思路和想法,第一道签 ...
- 大白话讲讲 Go 语言的 sync.Map(一)
阅读本文大约需要 4.25 分钟. 程序是枯燥乏味的. 在讲 sync.Map 之前,我们先说说什么是 map(映射). 我们每个人都有身份证号码,如果我需要从身份证号码查到对应的姓名,用 map 存 ...
- AutoCAD 2024下载及安装教程
安装教程 演示操作系统:Windows 11 *安装前请关闭所有杀毒软件,避免报错 1.解压[CAD2024.zip] 2.打开解压的[CAD2024]文件夹,打开[Setup]文件夹,运行[Setu ...
- git报错:SSL certificate problem: unable to get local issuer certificate
原因:在windows系统中git没有获取到ssl证书 解决方案 输入以下命令: git config --global http.sslBackend schannel 之后再执行操作就可以啦 另: ...
- 安装 配置 正向 解析 DNS方法
安装 配置 正向 解析 DNS方法 1,安装dhcp [root@localhost ~]#yum install bind* -y 2,关闭防火墙和selinux [root@localhost ~ ...
- 超详细的mysql总结(基本概念、DDL、DML)
开发中存在着各种数据,比如用户的个人信息.商品详情.购买记录,这些数据都要以一定的方式储存,如果以文本的形式储存,每一次获取都要读取文件,如果信息有修改则需要直接修改文本,大量的数据会需要保存大量的文 ...
- VMware中的虚拟机Debian10的服务器配置,使主机(win10)能够通过本地域名(如www.xxx.com)访问该服务器
VMware中的虚拟机Debian10的服务器配置,使主机(win10)能够通过本地域名(如www.xxx.com)访问该服务器 安装过程 下载debian-10.13.0-amd64-DVD-1.i ...
- CSS实现文字描边效果
一.介绍最近在一个项目的宣传页中,设计师使用了文字描边效果,之前我确实没有实现过文字的描边效果,然后我在查阅资料后,知道了实现方法.文字描边分为两种:内外双描边和单外描边,也就是指在给文字加上描边效果 ...