Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- int n, k;
- cin >> n >> k;
- vector<pair<double, double>> v(n);
- for(int i = 0; i < n; i++) {
- cin >> v[i].first;
- }
- for(int i = 0; i < n; i++) {
- cin >> v[i].second;
- }
- double ss = 0;
- for(int i = 0; i < n; i++) {
- ss += v[i].first * v[i].second;
- }
- if(k == 0) {
- cout << ss << "\n";
- return 0;
- }
- sort(v.begin(), v.end());
- vector<double> prob(n), ps(n);
- ps[0] = v[0].second;
- prob[0] = (v[0].first * v[0].second);
- for(int i = 1; i < n; i++) {
- ps[i] = ps[i - 1] + v[i].second;
- prob[i] = prob[i - 1] + (v[i].first * v[i].second);
- }
- int qnt = lower_bound(v.begin(), v.end(), make_pair(ss, 0.0)) - v.begin();
- while(k--) {
- while(v[qnt].first < ss) {
- qnt++;
- }
- ss = ss * ps[qnt - 1] + (prob[n - 1] - prob[qnt - 1]);
- }
- cout << ss << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement