/*
অভিজ্ঞতা একটি কঠিন শিক্ষক,
সে প্রথমে তোমার পরীক্ষা নেয় এবং
পরে তার পাঠ দেয়।
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define el '\n'
#define f(a, b) for (int i = a; i < b; i++)
#define fr(a, b) for (int i = a; i >= b; i--)
#define vi vector<int>
void solve();
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
clock_t z = clock();
int t = 1;
// cin >> t;
while (t--)
solve();
cerr << "Run Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC);
return 0;
}
void solve()
{
int n, k;
cin >> n >> k;
int a[n], b[n], j[k];
f(0, n) cin >> a[i];
f(0, n) cin >> b[i];
f(0, n) a[i]--;
f(0, k) j[i] = -1;
f(0, n) if (j[a[i]] == (-1) or b[i] > b[j[a[i]]]) j[a[i]] = i;
f(0, k) if (j[i] != (-1)) b[j[i]] = 0;
sort(b, b + n);
n = 0;
f(0, k) n += b[i];
cout << n << el;
return;
}
1032. Stream of Characters | 987. Vertical Order Traversal of a Binary Tree |
952. Largest Component Size by Common Factor | 212. Word Search II |
174. Dungeon Game | 127. Word Ladder |
123. Best Time to Buy and Sell Stock III | 85. Maximal Rectangle |
84. Largest Rectangle in Histogram | 60. Permutation Sequence |
42. Trapping Rain Water | 32. Longest Valid Parentheses |
Cutting a material | Bubble Sort |
Number of triangles | AND path in a binary tree |
Factorial equations | Removal of vertices |
Happy segments | Cyclic shifts |
Zoos | Build a graph |
Almost correct bracket sequence | Count of integers |
Differences of the permutations | Doctor's Secret |
Back to School | I am Easy |
Teddy and Tweety | Partitioning binary strings |