-
Notifications
You must be signed in to change notification settings - Fork 0
/
max_nutrition.cpp
59 lines (58 loc) · 1.07 KB
/
max_nutrition.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
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
// your code goes here
int t;
cin >> t;
// int n;
// vector<int>a,d,b;
while (t > 0) {
int i;
int n;
vector<int> a, d, b;
cin >> n;
int num;
for (i = 0; i < n; i++) {
cin >> num;
a.push_back(num);
}
for (i = 0; i < n; i++) {
cin >> num;
b.push_back(num);
}
d = a;
sort(d.begin(), d.end());
int m = d.size();
int sum = 0;
unordered_map<int, int> mp;
for (i = 0; i < m; i++) {
if (i == 0) {
continue;
} else {
if (d[i] == d[i - 1]) {
d.erase(d.begin() + i);
i--;
m--;
}
}
}
// for(i=0; i<m; i++){
// cout<<d[i]<<"\t";
// }
for (i = 0; i < d.size(); i++) {
mp[d[i]] = 0;
}
for (i = 0; i < b.size(); i++) {
mp[a[i]] = max(mp[a[i]], b[i]);
}
for (i = 0; i < d.size(); i++) {
if (mp[d[i]] > 0) {
sum = sum + mp[d[i]];
}
}
cout << sum << endl;
t--;
}
return 0;
}