#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
pair<int,int>a[];
bool cmp(pair<int,int>a,pair<int,int>b){
if(a.second!=b.second)
return a.second>b.second;//按照时间从大到小排序
return a.first<b.first;
}
map<int,int>fa;
int find_(int x){
if(!fa[x])
return x;
return fa[x]=find_(fa[x]);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin>>n;
for(int i=;i<=n;++i)
cin>>a[i].first;
for(int i=;i<=n;++i)
cin>>a[i].second;
sort(a+,a++n,cmp);
long long ans=;
for(int i=;i<=n;++i){//按照个数从小到大排序,可能会让个数小而时间多的不停++,而原本个数多时间少的却加的不多,导致答案不对,先搞时间多的代价大的才是正解
int x=find_(a[i].first);
if(a[i].first==x){//当前个数唯一
int y=find_(a[i].first+);//把它合并到+1的位置
fa[x]=y;
}
else{//当前已有,放到最近一个比它大且没别选中的位置
ans+=1ll*(x-a[i].first)*a[i].second;//更新贡献
int y=find_(x+);//合并到+1的位置(原本的位置更新后被占了)
fa[x]=y;
}
}
cout<<ans;
return ;
}

Codeforces Round #623 (Div. 1, based on VK Cup 2019-2020 - Elimination Round, Engine)A(模拟,并查集)的更多相关文章

  1. Codeforces Round 623(Div. 2,based on VK Cup 2019-2020 - Elimination Round,Engine)D. Recommendations

    VK news recommendation system daily selects interesting publications of one of n disjoint categories ...

  2. Codeforces Round #623 (Div. 2, based on VK Cup 2019-2020 - Elimination Round, Engine)

    A. Dead Pixel(思路) 思路 题意:给我们一个m*n的表格,又给了我们表格中的一个点a,其坐标为(x, y),问在这个表格中选择一个不包括改点a的最大面积的矩形,输出这个最大面积 分析:很 ...

  3. Codeforces Round #623 (Div. 2, based on VK Cup 2019-2020 - Elimination Round, Engine) C. Restoring

    C. Restoring Permutation time limit per test1 second memory limit per test256 megabytes inputstandar ...

  4. Codeforces Round #623 (Div. 2, based on VK Cup 2019-2020 - Elimination Round, Engine) B. Homecoming

    After a long party Petya decided to return home, but he turned out to be at the opposite end of the ...

  5. Codeforces Round #623 (Div. 2, based on VK Cup 2019-2020 - Elimination Round, Engine) A Dead Pixel

    讨论坏点的左右上下的矩形大小. #include <bits/stdc++.h> using namespace std; int main() { int t; cin >> ...

  6. Codeforces Round #681 (Div. 1, based on VK Cup 2019-2020 - Final) B. Identify the Operations (模拟,双向链表)

    题意:给你一组不重复的序列\(a\),每次可以选择一个数删除它左边或右边的一个数,并将选择的数append到数组\(b\)中,现在给你数组\(b\),问有多少种方案数得到\(b\). 题解:我们可以记 ...

  7. Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final)【ABCDF】

    比赛链接:https://codeforces.com/contest/1443 A. Kids Seating 题意 构造一个大小为 \(n\) 的数组使得任意两个数既不互质也不相互整除,要求所有数 ...

  8. Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final) D. Extreme Subtraction (贪心)

    题意:有一个长度为\(n\)的序列,可以任意取\(k(1\le k\le n)\),对序列前\(k\)项或者后\(k\)减\(1\),可以进行任意次操作,问是否可以使所有元素都变成\(0\). 题解: ...

  9. Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final) C. The Delivery Dilemma (贪心,结构体排序)

    题意:你要买\(n\)份午饭,你可以选择自己去买,或者叫外卖,每份午饭\(i\)自己去买需要消耗时间\(b_i\),叫外卖需要\(a_i\),外卖可以同时送,自己只能买完一份后回家再去买下一份,问最少 ...

随机推荐

  1. ROS 环境变量配置

    unbantu16.04 linux 版本,  ros系统 kinetic版本 1. ros系统可以通过rospack find  package_name  /   rosrun package_n ...

  2. maven的核心概念——聚合

    第十六章聚合 16.1 为什么要使用聚合 将多个工程拆分为模块后,需要手动逐个安装到仓库后依赖才能够生效.修改源码后也需要逐个手动进行clean操作.而使用了聚合之后就可以批量进行Maven工程的安装 ...

  3. JN_0014:win10命令窗口以管理员方式启动

    1,先打开命令窗口 2,固定到任务栏 3,右键任务栏图标 4,右键命令提示符, 5,选择以管理员方式启动.

  4. PHP 实现遍历出目录及其子文件

    手册(有PHP4的实现方式哦):https://www.php.net/manual/zh/function.scandir.php 直接附代码吧PHP5和PHP7 直接有scandir()函数,遍历 ...

  5. ng--tolist说明

    起步 下载模板: git clone https://github.com/tastejs/todomvc-app-template.git --depth 1 初始化项目: ng new todom ...

  6. springMVC请求访问的整个过程

    //以上个随笔(springMVC项目配置文件)为基础,详述springMVC请求的整个过程流向 web.xml                                            ...

  7. 大json直接序列化成dataset

    rtnDs= JsonConvert.DeserializeObject<DataSet>(strBuff);

  8. Web_0003:关于PHP上传文件大小的限制

    相关设置如下: 1,file_uploads = on  是否允许通过HTTP上传文件的开关,默认为ON即是开 2,upload_max_filesize = 8m ; 即允许上传文件大小的最大值.默 ...

  9. ansible安装-本机测试

    环境:centos7 yum源:网络yum源 安装: 默认yum安装,也可以自己编译安装 yum -y install ansible 本机测试: [root@localhost ~]# ansibl ...

  10. C 库函数 - fmod()

    C 库函数 - fmod() 转自: C 标准库 - <math.h> 描述 C 库函数 double fmod(double x, double y) 返回 x 除以 y 的余数. 声明 ...