zoukankan      html  css  js  c++  java
  • A. Recommendations

    VK news recommendation system daily selects interesting publications of one of nn disjoint categories for each user. Each publication belongs to exactly one category. For each category ii batch algorithm selects aiai 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 ii-th category within titi 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 nn — the number of news categories (1n2000001≤n≤200000).

    The second line of input consists of nn integers aiai — the number of publications of ii-th category selected by the batch algorithm (1ai1091≤ai≤109).

    The third line of input consists of nn integers titi — time it takes for targeted algorithm to find one new publication of category ii (1ti105)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
    input
    Copy
    5
    3 7 9 7 8
    5 2 5 7 5
    
    output
    Copy
    6
    
    input
    Copy
    5
    1 2 3 4 5
    1 1 1 1 1
    
    output
    Copy
    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.

    ai排下序,对应的t值有重复的就算一下加一位所需的值

    比如样例1,3 7 9 7 8,3没有重复不用管,7有重复,下个数字是8,原来的8对应的值是5,大于之前7对应的2,所以之前那个7再往下数就是9,9对应的值是5,大于最开始从7加上来的所对应的值,7再往下数就是10,无重复,所以值是2*3=6

    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <string>
    #include <set>
    #include <queue>
    #include <map>
    #include <sstream>
    #include <cstdio>
    #include <cstring>
    #include <numeric>
    #include <cmath>
    #include <iomanip>
    #include <deque>
    #include <bitset>
    //#include <unordered_set>
    //#include <unordered_map>
    //#include <bits/stdc++.h>
    //#include <xfunctional>
    #define ll              long long
    #define PII             pair<int, int>
    #define rep(i,a,b)      for(int  i=a;i<=b;i++)
    #define dec(i,a,b)      for(int  i=a;i>=b;i--)
    #define pb              push_back
    #define mk              make_pair
    using namespace std;
    int dir1[6][2] = { { 0,1 } ,{ 0,-1 },{ 1,0 },{ -1,0 },{ 1,1 },{ -1,1 } };
    int dir2[6][2] = { { 0,1 } ,{ 0,-1 },{ 1,0 },{ -1,0 },{ 1,-1 },{ -1,-1 } };
    const long long INF = 0x7f7f7f7f7f7f7f7f;
    const int inf = 0x3f3f3f3f;
    const double pi = 3.14159265358979;
    const int mod = 100007;
    const int N = 200005;
    //if(x<0 || x>=r || y<0 || y>=c)
    
    inline ll read()
    {
        ll x = 0; bool f = true; char c = getchar();
        while (c < '0' || c > '9') { if (c == '-') f = false; c = getchar(); }
        while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
        return f ? x : -x;
    }
    ll gcd(ll m, ll n)
    {
        return n == 0 ? m : gcd(n, m % n);
    }
    struct node
    {
        int x, y;
    };
    node a[N];
    int n;
    bool cmp(node x, node y)
    {
        return x.x < y.x;
    }
    int main()
    {
        cin >> n;
        rep(i,1,n)
            a[i].x = read();
        rep(i, 1, n)
            a[i].y = read();
        sort(a + 1, a + n + 1, cmp);
        priority_queue<int> q;
        ll cur = 1, cnt = 0, ans = 0, tmp = 0;
        while (!q.empty() || cur < n)
        {
            cnt++;
            if (q.empty())
            {
                cnt = a[cur].x;
                while (cur <= n && cnt == a[cur].x)
                {
                    tmp += a[cur].y;
                    q.push(a[cur].y);
                    cur++;
                }
            }
            else
            {
                while (cnt == a[cur].x && cur <= n)
                {
                    tmp += a[cur].y;
                    q.push(a[cur].y);
                    cur++;
                }
            }
            tmp -= q.top();
            q.pop();
            ans += tmp;
        }
        cout << ans << endl;
        return 0;
    }
  • 相关阅读:
    如何用视频云技术,搞一个爆红的 “反应视频” 项目?
    停车场事故频频,AI 达人将摄像头变身安全卫士
    WebRTC 传输安全机制第二话:深入显出 SRTP 协议
    阿里云视频云 Retina 多媒体 AI 体验馆开张啦!
    20 岁发表 SCI 的学霸,梦想用算法改变世界
    阿里绩效考核,简单到不可思议,员工死心塌地跟你干!(转)
    【官方】阿里巴巴合伙人制度全文(转)
    blob视频地址如何下载(转)
    软件开发项目规划时,SA、SD与SE的区别与重要性 【转】
    一分钟看懂公有云和私有云的区别
  • 原文地址:https://www.cnblogs.com/dealer/p/12776443.html
Copyright © 2011-2022 走看看