-
Notifications
You must be signed in to change notification settings - Fork 0
/
codeforces557c.cpp
117 lines (114 loc) · 2.43 KB
/
codeforces557c.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <bits/stdc++.h>
#define MOD (1000000007)
#define EPS (1e-9)
#define INF (2117117117)
#define LLINF (2117117117117117117LL)
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define loop(i,j,n) for(i = j;i < n;i++)
#define fi first
#define sc second
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll,ll> pairll;
typedef pair<int,char> pairic;
//FAST INTEGER INPUT
template <class T>
int readInt ( T &x ) {
bool minus = false;
T result = 0;
char ch;
ch = getchar();
while (true) {
if (ch == '-') break;
if (ch >= '0' && ch <= '9') break;
ch = getchar();
}
if (ch == '-') minus = true; else result = ch-'0';
while (true) {
ch = getchar();
if (ch < '0' || ch > '9') break;
result = result*10 + (ch - '0');
}
if (minus)
x = -result;
else
x = result;
return 0;
}
//GENERATE nCr TRIANGLE
ll comb[4001][4001];
int ncr(){
int i,j;
for(i = 0; i < 4001; i++)
comb[i][0] = comb[0][i] = comb[i][i] = 1;
for(i = 1; i < 4001; i++)
for(j = 1; j < i; j++)
comb[i][j] = (comb[i-1][j-1] + comb[i-1][j]) % MOD;
return 1;
}
class legs{
public:
ll l,d;
legs(int a,int b){
l = a;b = d;
}
legs(){
l = 0;d = 0;
}
};
bool cmp(legs a,legs b){
if(a.l < b.l)
return true;
else
return false;
}
ll cnt[201],tmpcnt[201],e[100005],tot,n,i,k,j,minimum,temp,m,r;
int main(){
readInt(n);
legs a[n];
loop(i,0,n)readInt(a[i].l);
loop(i,0,n)readInt(a[i].d);
sort(a,a+n,cmp);
tot = 0;
for(i = n-2;i >= 0;i--){
tot += a[i+1].d;
e[i] = tot;
}
minimum = tot+a[0].d+1;
loop(i,0,n){
cnt[a[i].d]++;
loop(j,0,201)
tmpcnt[j] = cnt[j];
temp = e[i];
k = 0;
for(j = i;j >= 0;j--)
if(a[j].l == a[i].l){
tmpcnt[a[j].d]--;
k++;
}
else
break;
if(2*k <= (i+1)){
m = 1+(i+1)-2*k;
j = 0;
while(m){
if(tmpcnt[j] <= m){
m -= tmpcnt[j];
temp += j*tmpcnt[j];
j++;
}
else{
temp += m*j;
m = 0;
}
}
}
if(temp < minimum )
minimum = temp;
}
cout<<minimum;
}