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;
    }
  • 相关阅读:
    EBS接口程序调试
    FORM级别和数据库级别的Trace
    详解EBS接口开发之供应商导入(补充)--供应商银行账户更新
    详解EBS接口开发之库事务处理带提前发运通知(ASN)采购接收入库-补充
    详解EBS接口开发之库存事务处理采购接收--补充
    采购接收会计期间未打开报错分析
    供应商默认发运地和开票地更新
    Linux下which、whereis、locate、find 命令查找文件
    sql AND 和 OR 运算符用于基于一个以上的条件对记录进行过滤
    premake构造工具
  • 原文地址:https://www.cnblogs.com/dealer/p/12776443.html
Copyright © 2011-2022 走看看