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 for each user. Each publication belongs to exactly one category. For each category i batch algorithm selects ai publications.
The latest A/B test suggests that users are reading recommended publications more actively if each category has a different number of publications within daily recommendations. The targeted algorithm can find a single interesting publication of i-th category within ti seconds.
What is the minimum total time necessary to add publications to the result of batch algorithm execution, so all categories have a different number of publications? You can’t remove publications recommended by the batch algorithm.
Input
The first line of input consists of single integer n — the number of news categories (1≤n≤200000).
The second line of input consists of n integers ai — the number of publications of i-th category selected by the batch algorithm (1≤ai≤109).
The third line of input consists of n integers ti — time it takes for targeted algorithm to find one new publication of category i (1≤ti≤105).
Output
Print one integer — the minimal required time for the targeted algorithm to get rid of categories with the same size.
Examples
inputCopy
5
3 7 9 7 8
5 2 5 7 5
outputCopy
6
inputCopy
5
1 2 3 4 5
1 1 1 1 1
outputCopy
0
Note
In the first example, it is possible to find three publications of the second type, which will take 6 seconds.
In the second example, all news categories contain a different number of publications.
优先队列,每次都让某一位上的全职最小的加1,2,3然后处理。
#include <bits/stdc++.h>
using namespace std;
int n, t, a[3000000];
struct node
{
int first, second;
bool operator<(const node &b) const
{
if (first == b.first)
return second < b.second;
else
return first > b.first;
}
};
priority_queue<node> ms;
int main()
{
cin >> n;
for (int i = 0; i < n; ++i)
{
cin >> a[i];
}
for (int i = 0; i < n; ++i)
{
int b;
cin >> b;
ms.push(node{a[i], b});
}
long long cnt = 0;
while (ms.size())
{
auto po = ms.top();
ms.pop();
//cout << po.first << " " << po.second << endl;
//cout << 1 << endl;
if (ms.empty())
break;
int f=1;
while (po.first == ms.top().first && ms.size())
{
auto pi = ms.top();
//cout<<pi.first + 1<<" "<<pi.second<<endl;
ms.pop();
ms.push(node{pi.first + f, pi.second});
cnt += pi.second;
f++;
// cout << cnt << endl;
// cout<<ms.top().first<<endl;
// cout << ms.size() << endl;
}
}
cout << cnt << endl;
}
上分代码的思路确实有问题,时间复杂度太高。思路差不多,都是先处理权值大的,让权值小移动。
#include <bits/stdc++.h>
using namespace std;
int n, t;
struct node
{
int data;
long long cost;
bool operator<(const node &b) const
{
if (cost == b.cost)
return data < b.data;
else
return cost > b.cost;
}
} a[3000000];
map<int, int> fa;
int find(int a)
{
if (fa[a] == 0)
return a;
else
return fa[a] = find(fa[a]);
}
void unite(int x, int y)
{
x = find(x);
y = find(y);
if (x != y)
fa[x] = y;
}
int main()
{
cin >> n;
fa.clear();
for (int i = 0; i < n; ++i)
scanf("%d", &a[i].data);
for (int i = 0; i < n; ++i)
scanf("%lld", &a[i].cost);
sort(a, a + n);
long long ans = 0;
for (int i = 0; i < n; i++)
{
int x=find(a[i].data) ;
ans += a[i].cost * (x- a[i].data);
unite(x,x+1);
}
cout << ans << endl;
}
Codeforces Round 623(Div. 2,based on VK Cup 2019-2020 - Elimination Round,Engine)D. Recommendations的更多相关文章
- 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<]; bool cmp( ...
- 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. 2, based on VK Cup 2019-2020 - Final)【ABCDF】
比赛链接:https://codeforces.com/contest/1443 A. Kids Seating 题意 构造一个大小为 \(n\) 的数组使得任意两个数既不互质也不相互整除,要求所有数 ...
- 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) 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\),外卖可以同时送,自己只能买完一份后回家再去买下一份,问最少 ...
随机推荐
- Mysql大数据量问题与解决
今日格言:了解了为什么,问题就解决了一半. Mysql 单表适合的最大数据量是多少? 我们说 Mysql 单表适合存储的最大数据量,自然不是说能够存储的最大数据量,如果是说能够存储的最大量,那么,如果 ...
- ConcurrentHashMap和 CopyOnWriteArrayList提供线程安全性和可伸缩性 以及 同步的集合类 Hashtable 和 Vector Collections.synchronizedMap 和 Collections.synchronizedList 区别缺点
ConcurrentHashMap和 CopyOnWriteArrayList提供线程安全性和可伸缩性 DougLea的 util.concurrent 包除了包含许多其他有用的并发构造块之外,还包含 ...
- 查看jdk 线程 日志
命令:jstack(查看线程).jmap(查看内存)和jstat(性能分析)命令 这些命令 必须 在 linux jdk bin 路径 下执行 eq: ./jstack 10303 即可 如果想把 ...
- pytorch cheatsheet
- Ignatius and the Princess IV HDU 1029
题目大意: n个数字,找出其中至少出现(n+1)/2次的数字,并且保证n是奇数. 题解:这道题数组是不能用的,因为题目没有明确输入的数据范围,比如输入了一个1e9,数组肯定开不了这么大.所以要用map ...
- Postman:Pre-request Script
Pre-request Script:前置处理,会在发出请求前执行,主要用在生成一些动态参数. 例如:api接口都会有签名校验,这个校验在我们api测试的时候很不方便,这里可以利用 postman 前 ...
- SpringCloud(七)超时、重试
一.Ribbon(单独配置) 可以通过ribbon.xx来进行全局配置.也可以通过服务名.ribbon.xx来对指定服务配置 全局配置: ribbon: ConnectTimeout: 3000 #连 ...
- 从零开始建图床 minio
图床 图床可以参考知乎这篇文章 一些小众图床有空空间免费,但不知道什么时候会挂掉.前些年用过的极简图床,现在也销声匿迹: 大厂提供的有限免费空间,七牛云10G空间,10Gb/月 流量免费:但如果使用h ...
- search(7)- elastic4s-search-filter模式
现在我们可以开始探讨ES的核心环节:搜索search了.search又分filter,query两种模式.filter模式即筛选模式:将符合筛选条件的记录作为结果找出来.query模式则分两个步骤:先 ...
- Java 解析 xml 常见的4中方式:DOM SAX JDOM DOM4J
Java 四种解析 XML 的特点 1.DOM 解析: 形成了树结构,有助于更好的理解.掌握,且代码容易编写. 解析过程中,树结构保存在内存中,方便修改. 2.SAX 解析: 采用事件驱动模式,对内存 ...