【codeforces 557C Arthur and Table】+ 思维
来源:互联网 发布:单片机 延时 远离 编辑:程序博客网 时间:2024/06/02 22:48
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
总的贡献 - 非必要贡献(即该长度值L的贡献~以及小于该长度小于L的价值较大的贡献~)= 即为该次贡献~~=.=
AC代码:
#include<cstdio>#include<algorithm>using namespace std;typedef long long LL;const int MAXN = 1e5 + 10;const LL INF = 0x3f3f3f3f;struct node{ int x,y;}st[MAXN];LL num[210]; // 每种贡献的桌腿个数bool cmp(node i,node j){ return i.x < j.x;}int main(){ LL N,cut = 0; scanf("%lld",&N); for(int i = 1 ; i <= N; i++) scanf("%d",&st[i].x); for(int i = 1 ; i <= N; i++){ scanf("%d",&st[i].y); cut += st[i].y; } sort(st + 1 , st + 1 + N, cmp); LL n = 1,ans = INF,k; while(n <= N){ LL nl = 0,sum = cut; for(int i = n; st[i].x == st[n].x; i++){ ++nl; sum -= st[i].y; } --nl; for(int i = 200 ; i >= 1 && nl > 0 ;i--){ sum -= min(nl,num[i]) * i; nl -= num[i]; } ans = min(ans,sum); for(k = n ; st[k].x == st[n].x ; k++) num[st[k].y]++; n = k; } printf("%lld\n",ans); return 0;}
- 【codeforces 557C Arthur and Table】+ 思维
- Codeforces 557C Arthur and Table【思维】
- Codeforces 557C Arthur and Table 砍桌腿
- codeforces 557c Arthur and Table
- Codeforces 557C Arthur and Table
- 【35.29%】【codeforces 557C】Arthur and Table
- codeforces #311 C 557C. Arthur and Table(枚举+贪心)
- Codeforces 557C Arthur and Table 乱搞题
- Codeforces 557C Arthur and Table 【树状数组 + 二分】
- 【贪心+线段树】Codeforces 557C Arthur and Table
- 557C Arthur and Table
- CodeForces#311 C. Arthur and Table
- Codeforces Round #311 (Div. 2) C. Arthur and Table
- Codeforces Round #311 (Div. 2) C. Arthur and Table
- codeforces 311(div2)C-Arthur and Table
- Codeforces Round #311 (Div. 2)-C. Arthur and Table
- Codeforces 557C Arthur and Table 暴力水过得题。。。
- CF 557C(Arthur and Table-直接暴力)
- tomcat-7.0源码安装配置
- 2016年12月7日学习总结----今日知识点总结
- 运放知识
- 系统学习Unix网络编程
- 让QGraphicsItemGroup中的item处理自己的事件
- 【codeforces 557C Arthur and Table】+ 思维
- 复杂的c-c++声明
- tensorflow 在 win7 64位的配置
- Word图标不能正常显示
- 【已解决】macOS10.12.1的gitk报错,无法打开
- Junit使用过程中需要注意的诡异bug以及处理办法
- 最短路算法(1)- bellman ford算法
- Abstract Factory(抽象工厂)实践
- LeetCode 217. Contains Duplicate(Java)