Codeforces 557C Arthur and Table

原创 2015年11月20日 23:03:05

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.

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

解题思路:最近智商弱到爆啊,只能做点水题来水水了,还写错了个下标,调了半天。。。。。

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
using namespace std;
const int maxn = 100010;
vector<int> vec[maxn];
priority_queue<int, vector<int>, less<int> > pq;
int l[maxn], d[maxn], sum[maxn];
vector<int> vv;

int main() {

    //freopen("aa.in", "r", stdin);

    int n;
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i) {
        scanf("%d", &l[i]);
    }
    int tot = 0;
    int ans = 0x3f3f3f3f;
    for(int i = 1; i <= n; ++i) {
        scanf("%d", &d[i]);
        tot += d[i];
        vec[l[i]].push_back(d[i]);
        sum[l[i]] += d[i];
    }
    for(int i = 1; i <= 100000; ++i) {
        if(sum[i] == 0) continue;
        int t = sum[i];
        int s = vec[i].size() - 1;
        vv.clear();
        int tt = 0;
        while(s > 0 && !pq.empty()) {
            tt += pq.top();
            vv.push_back(pq.top());
            pq.pop();
            s--;
        }
        t += tt;
        ans = min(ans, tot - t);
        for(int j = 0; j < (int)vv.size(); ++j) {
            pq.push(vv[j]);
        }
        for(int j = 0; j < (int)vec[i].size(); ++j) {
            pq.push(vec[i][j]);
        }
    }
    printf("%d\n", ans);
    return 0;
}

CodeForces - 557C. Arthur and Table

C. Arthur and Table time limit per test1 second memory limit per test256 megabytes inputstandard ...
  • WwyY9
  • WwyY9
  • 2017年08月05日 23:25
  • 99

Codeforces 557C Arthur and Table 乱搞题

题意: 如果最长长度的凳脚数量超过总凳脚数的一半,则认为这个凳子是稳定的。 现在有张凳子,有n个凳脚,分别分出长度和砍掉该凳脚的费用。 问你要使得凳子稳定的最小费用。 思路: 其实是...

codeforces #311 C 557C. Arthur and Table(枚举+贪心)

题目链接: 点击打开链接 题目大意: 给出一个桌子,有n个腿,每个腿的长度是l,拆掉这条腿的花费是d,当最长的腿占腿总数大于其他腿的总数,那么合法,问如何才能花费最小到达合法情况 题目分析: ...

557C Arthur and Table

题意:题目给出的桌子的n条长度不一的腿,以及打断每条腿所需的花费。要求在最小的花费下,使桌子达到平衡。平衡的条件是最大腿的个数要大于总的腿数的一半。 思路:这道题刚开始往dp上考虑,结果怎么搞,都找...

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 standa...

CodeForces - 557CArthur and Table(贪心+桶排或权值线段树)

C. Arthur and Tabletime limit per test1 second memory limit per test256 megabytes inputstandard in...

暴力枚举 C. Arthur and Table

链接:http://codeforces.com/problemset/problem/557/C 直接暴力枚举即可 注意d的范围为1-200 这样维护就比较简单了 代码: #include...

codeforces 525 D Arthur and Walls

codeforces 525 D Arthur and Walls 题意: 给出一个n*m的表格,里面有'*'和'.',求把最少的'*'移除掉,使得'.'所在的连通块是矩形。 限制: 1 ...
  • whai362
  • whai362
  • 2015年04月02日 10:51
  • 464

Codeforces 508E Arthur and Brackets

题意: 给出括号序列中每个右括号可能离对应左括号多远  求这个括号序列 思路: 记忆化搜索解决  用f[l][r]表示对于第l个左括号到第r个左括号区间最前面的左括号与其对应右括号的距离 状态...

Codeforces Round #297 (Div. 2) -- D. Arthur and Walls (判断矩形)

D. Arthur and Walls time limit per test 2 seconds memory limit per test 512 megabytes ...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Codeforces 557C Arthur and Table
举报原因:
原因补充:

(最多只允许输入30个字)