zoukankan      html  css  js  c++  java
  • Codeforces Round #311 (Div. 2)C. Arthur and Table

    C. Arthur and Table
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable.

    In total the table Arthur bought has n legs, the length of the i-th leg is li.

    Arthur decided to make the table stable and remove some legs. For each of them Arthur determined number di — the amount of energy that he spends to remove the i-th leg.

    A table with k legs is assumed to be stable if there are more than half legs of the maximum length. For example, to make a table with 5 legs stable, you need to make sure it has at least three (out of these five) legs of the maximum length. Also, a table with one leg is always stable and a table with two legs is stable if and only if they have the same lengths.

    Your task is to help Arthur and count the minimum number of energy units Arthur should spend on making the table stable.

    Input

    The first line of the input contains integer n (1 ≤ n ≤ 105) — the initial number of legs in the table Arthur bought.

    The second line of the input contains a sequence of n integers li (1 ≤ li ≤ 105), where li is equal to the length of the i-th leg of the table.

    The third line of the input contains a sequence of n integers di (1 ≤ di ≤ 200), where di is the number of energy units that Arthur spends on removing the i-th leg off the table.

    Output

    Print a single integer — the minimum number of energy units that Arthur needs to spend in order to make the table stable.

    Examples
    input
    2
    1 5
    3 2
    output
    2
    input
    3
    2 4 4
    1 1 1
    output
    0
    input
    6
    2 2 1 1 3 3
    4 3 5 5 2 1
    output
    8

    枚举作为最大桌子腿的长度,比如第3个样例我们可以枚举 3 2 1。   当枚举到2 的时候,3就必然要删除...

    所以我们可以 排序,multiset瞎搞了

    /* ***********************************************
    Author        :guanjun
    Created Time  :2016/8/14 9:42:21
    File Name     :cf311c.cpp
    ************************************************ */
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <stdio.h>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <string>
    #include <math.h>
    #include <stdlib.h>
    #include <iomanip>
    #include <list>
    #include <deque>
    #include <stack>
    #define ull unsigned long long
    #define ll long long
    #define mod 90001
    #define INF 0x3f3f3f3f
    #define maxn 100010
    #define cle(a) memset(a,0,sizeof(a))
    const ull inf = 1LL << 61;
    const double eps=1e-5;
    using namespace std;
    priority_queue<int,vector<int>,greater<int> >pq;
    struct Node{
        int x,y;
    };
    struct cmp{
        bool operator()(int a,int b){
            return a>b;
        }
    };
    multiset<int,cmp>s;
    vector<int>v[maxn];
    int vis[maxn];
    int x[maxn];
    int y[maxn];
    int main()
    {
        #ifndef ONLINE_JUDGE
        freopen("in.txt","r",stdin);
        #endif
        //freopen("out.txt","w",stdout);
        int n;
        cin>>n;
        int sum=0,Min=INF,Max=0;
        for(int i=1;i<=n;i++){
            scanf("%d",&x[i]);
        }
        for(int i=1;i<=n;i++){
            scanf("%d",&y[i]);
            v[x[i]].push_back(y[i]);
            sum+=y[i];
            s.insert(y[i]);
            Min=min(Min,x[i]);
            Max=max(Max,x[i]);
        }
        if(n==2){
            if(x[1]==x[2])cout<<0<<endl;
            else cout<<min(y[1],y[2])<<endl;return 0;
        }
        int ans=INF;
        for(int i=Max;i>=Min;i--){
            int m=v[i].size();
            if(m>0&&!vis[i]){
                vis[i]=1;
                int tmp=0,tmp2=0;
                for(int j=0;j<m;j++){
                    auto pos=s.find(v[i][j]);
                    s.erase(pos);
                    tmp+=v[i][j];
                }
                int cnt=0;
                for(auto x:s){
                    if(cnt==m-1)break;
                    tmp+=x;
                    cnt++;
                }
                ans=min(ans,sum-tmp);
            }
        }
        if(ans==INF){
            cout<<0<<endl;
        }
        else cout<<ans<<endl;
        return 0;
    }

    注意 multiset删除某个value时 他会把值为value的全部删除..

    如果想只删除一个,那么可以加一个find,erase 一个值,具体看代码

  • 相关阅读:
    golang mod 导包
    grpc client 报错: code = Unimplemented desc = method *** not implemented
    golang读取email
    docker 使用
    在word中批量更改Mathtype公式的格式
    word中插入myth type公式行距变大的问题
    word中编辑论文公式对齐问题
    向别人学习
    机器学习 博文汇总
    matlab中如何用rand产生相同的随机数
  • 原文地址:https://www.cnblogs.com/pk28/p/5772104.html
Copyright © 2011-2022 走看看