Codeforces Round #623 (Div. 1, based on VK Cup 2019-2020 - Elimination Round, Engine)A(模拟,并查集)
#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(模拟,并查集)的更多相关文章
- 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 ...
- Codeforces Round #623 (Div. 2, based on VK Cup 2019-2020 - Elimination Round, Engine)
A. Dead Pixel(思路) 思路 题意:给我们一个m*n的表格,又给了我们表格中的一个点a,其坐标为(x, y),问在这个表格中选择一个不包括改点a的最大面积的矩形,输出这个最大面积 分析:很 ...
- 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 ...
- 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 ...
- 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 >> ...
- Codeforces Round #681 (Div. 1, based on VK Cup 2019-2020 - Final) B. Identify the Operations (模拟,双向链表)
题意:给你一组不重复的序列\(a\),每次可以选择一个数删除它左边或右边的一个数,并将选择的数append到数组\(b\)中,现在给你数组\(b\),问有多少种方案数得到\(b\). 题解:我们可以记 ...
- Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final)【ABCDF】
比赛链接:https://codeforces.com/contest/1443 A. Kids Seating 题意 构造一个大小为 \(n\) 的数组使得任意两个数既不互质也不相互整除,要求所有数 ...
- 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\). 题解: ...
- Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final) C. The Delivery Dilemma (贪心,结构体排序)
题意:你要买\(n\)份午饭,你可以选择自己去买,或者叫外卖,每份午饭\(i\)自己去买需要消耗时间\(b_i\),叫外卖需要\(a_i\),外卖可以同时送,自己只能买完一份后回家再去买下一份,问最少 ...
随机推荐
- HTML表格概念、语法、操作、案例
创建两行三列表格 <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...
- day8 编码2
#!/usr/bin/env python # -*- coding:utf-8 -*- #str --->byte encode 编码 s = '二哥' b = s.encode('utf-8 ...
- c#---out参数
一个方法有多个返回值时,返回值类型相同可以返回一个数组 static void Main(string[] args) { , , , , , , , , , }; int[] result = Ge ...
- opencv —— split、merge 通道的分离与合并
对于三通道或四通道图像,有时要对某一通道的像素值进行修改或展示,这就需要进行通道分离操作.修改后,若要进行结果展示,就需要重新将各通道合并. 通道分离:split 函数 void split (Inp ...
- javascript 基础整理
js编码标准 参考 数据类型 注意事项
- 项目启动时报错:java.io.EOFException
解决方案 删除Tomcat里面的work\Catalina\localhost下的项目文件内容即可解决 问题原因 原因是由于项目测试中class文件或者其它文件更新过频繁
- GHO文件安装到Vmware的两种姿势
1.使用 Ghost11.5.1.2269 将gho转换为vmdk文件(虚拟机硬盘),Vmware新建虚拟机自定义配置,然后添加已有的虚拟硬盘文件. 注意ghost的版本,如果你是用Ghost11.5 ...
- MY_0003:设置界面显示单位
1,设置单位
- 12 : API
Object 概念 所有类的顶级父类 存在于java.lang包中,这个包不需要我们手动导包 常用方法 toString() 默认返回 类名@地址 的格式,来展示对象的地址值,如:a00000. ...
- CF840D[Destiny] [主席树板子]
模板题,提供两种思路. 1.考虑它求得是 出现个数\(>\lfloor \frac{r-l+1}{k}\rfloor\) 的最小值 那么我们可以根据如果大于这个数那么你把这个区间数列排好序然后分 ...