CF 557C(Arthur and Table-直接暴力)
2015-07-04 19:39
399 查看
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.
Sample test(s)
input
output
input
output
input
output
直接暴力找就行。
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.
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<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<functional> #include<algorithm> #include<iostream> using namespace std; #define MAXN (100000+10) #define INF (2139062143) #define For(i,n) for(int i=1;i<=n;i++) int n,l[MAXN],d[MAXN]; pair<int,int> a[MAXN],b[MAXN]; int main() { // freopen("CF557C.in","r",stdin); cin>>n; int tot=0; For(i,n) scanf("%d",&l[i]); For(i,n) scanf("%d",&d[i]),tot+=d[i]; a[0]=b[0]=make_pair(0,0); a[n+1]=b[n+1]=make_pair(INF,INF); For(i,n) a[i]=make_pair(d[i],l[i]); For(i,n) b[i]=make_pair(l[i],d[i]); sort(a+1,a+1+n); sort(b+1,b+1+n); int p=0,len=0,ans=0; For(i,n) { p+=b[i].second;len++; if (b[i].first!=b[i+1].first) { int j=n; while (j&&len>1) { if (a[j].second<b[i].first) p+=a[j].first,len--; j--; } ans=max(ans,p); p=len=0; } } cout<<tot-ans<<endl; return 0; }
相关文章推荐
- GRBL八:STM32代码移植——串口
- Qt上第三方串口类QExtSerialPort的使用
- JAVA图形编程Swing之——JPanel绘图
- 使用指针方式进行数组排序 选择排序:
- Debian7离线升级bash漏洞—然后修复方法
- Java设计模式之单例模式k
- codeforces B. School Marks
- node C++扩展(2) 尝试翻译node官网文档
- Android优化之ViewStub
- MeteoInfoLab脚本示例:FY-3A AOD HDF数据
- 漫谈程序员系列:怎么告别“混日子”
- redhat5.5 openldap server 配置搭建
- JAVA常用类之——System和Runtime
- [leetcode] Subsets II
- C++ 中string.find() 函数的用法总结(转载)
- 结束?开始。
- LTE演进路线图
- 一个非常有用的辅助类 -- 阈值类的实现
- HTML标签head详解
- mfc控件总览(转)