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\n",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\n",minn);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

叶孤心丶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值