#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); ifstream cin("in.txt"); int n; cin>>n; int prof=0; vector a(n); for (int i=0;i> a[i]; } sort (a.begin(),a.end()); int b[n],c[n]; vector > v; for (int i=0;i>b[i]; cin>>c[i]; v.push_back(make_pair (c[i],b[i])); } sort (v.begin(),v.end()); cout << endl; for (int i=n-1;i>=0;i--){ int left_bound = 0; int right_bound = (int) a.size() - 1; int it = -1; while(left_bound <= right_bound) { int middle = (left_bound + right_bound) / 2; if(a[middle] > v[i].second) { right_bound = middle - 1; } else { left_bound = middle + 1; it = max(it, middle); } } if(it != -1) { a.erase(a.begin() + it); prof += v[i].first; } } cout<