• C. Arthur and Table(Codeforces Round #311 (Div. 2) 贪心)


    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 5legs 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.

    Sample test(s)
    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
    


           题意:总水量一定。有n个男孩,n个女孩。男孩的水是一样的,女孩的也是一样的,可是男孩的是女孩的两倍,有2*n个杯子。求最多能分给他们的总水量



    #include<iostream>
    #include<algorithm>
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    
    using namespace std;
    
    int n;
    struct node {
        int x;
        int y;
    } q[1001000];
    int v[201];
    int minn;
    int small;
    
    bool cmp(node a,node b) {
        return a.x > b.x;
    }
    
    int main() {
        while(scanf("%d",&n)!=EOF) {
                memset(v,0,sizeof(v));
            for(int i=0; i<n; i++) {
                scanf("%d",&q[i].x);
            }
            for(int i=0; i<n; i++) {
                scanf("%d",&q[i].y);
                v[q[i].y]++;
            }
            if(n == 2 && q[0].x!=q[1].x)
            {
                printf("%d
    ",min(q[0].y,q[1].y));
                continue;
            }
            sort(q,q+n,cmp);
            minn = 99999999;
            int cnt = 1;
            int sum = 0;
            int ans = 0;
            int pn = n;
            small = 0;
            v[q[0].y]--;
            ans = q[0].y;
            for(int i=1; i<n; i++) {
                if(q[i].x == q[i-1].x) {
                    v[q[i].y]--;
                    ans += q[i].y;
                    cnt++;
                } else {
                    pn -= cnt;
                    int num = pn - cnt + 1;
                    if(num>0) {
                        for(int j=1; j<=201; j++) {
                            if(v[j]>=num) {
                                small += num * j;
                                num = 0;
                                break;
                            } else {
                                small += v[j]*j;
                                num -= v[j];
                            }
                        }
                    }
                    small += sum;
                    minn = min(small,minn);
                    cnt = 1;
                    sum += ans;
                    ans = q[i].y;
                    v[q[i].y]--;
                    small = 0;
                }
            }
            minn = min(minn,sum);
            printf("%d
    ",minn);
        }
        return 0;
    }


  • 相关阅读:
    Python 图形化编程
    2020年全国中职学生技能大赛《网络空间安全》赛题5
    2020年全国中职学生技能大赛《网络空间安全》赛题4
    2020年全国中职学生技能大赛《网络空间安全》赛题2
    2020年全国中职学生技能大赛《网络空间安全》赛题3
    2020年全国中职学生技能大赛《网络空间安全》赛题6
    Kotlin四舍五入保留两位小数
    Centos7 安装CoreDNS
    有个同学让我帮他保留下数据
    蓝桥杯Java 特别数的和【第十届】【省赛】【B组】
  • 原文地址:https://www.cnblogs.com/blfbuaa/p/6979523.html
Copyright © 2020-2023  润新知