传送门:CodeForces-1315D
题目描述
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 $a_i$ 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 $t_i$ 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.
输入描述
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 $a_i$ — the number of publications of $i$-th category selected by the batch algorithm $(1≤a_i≤10^9)$.
The third line of input consists of n integers $t_i$ — time it takes for targeted algorithm to find one new publication of category $i$ $(1≤t_i≤10^5)$.
输出描述
Print one integer — the minimal required time for the targeted algorithm to get rid of categories with the same size.
思路分析
贪心的想,如果有很多个相同的元素,那么将花费最大的留在原地,其他+1肯定是最优的,可以用set来维护最值
样例输入
5
3 7 9 7 8
5 2 5 7 5
样例输出
6
AC代码
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <vector>
#include <string>
#include <cstdio>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define ls x<<1
#define rs x<<1|1
#define fi first
#define se second
#define ll long long
#define pb push_back
#define mp make_pair
#define fun function
#define vi vector<int>
#define lowbit(x) x&(-x)
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 10;
multiset<ll>q;
pair<ll, ll>a[N];
int main() {
IOS;
#ifdef xiaofan
freopen("1.in", "r", stdin);
freopen("1.out", "w", stdout);
#endif
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i].fi;
for (int i = 0; i < n; i++)
cin >> a[i].se;
sort(a, a + n);
int now = -1;
ll ans = 0, sum = 0;
for (int i = 0; i < n; i++) {
while (q.size() && now < a[i].fi) {
ll ma = *q.rbegin();
ans += sum - ma;
sum -= ma;
q.erase(q.find(ma));
now++;
}
q.insert(a[i].se);
sum += a[i].se;
now = a[i].fi;
}
while (q.size()) {
ll ma = *q.rbegin();
ans += sum - ma;
sum -= ma;
q.erase(q.find(ma));
}
cout << ans << endl;
return 0;
}