Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //https://codeforces.com/gym/102986/problem/F
- #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<int, long 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;
- }
- long 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;
- }
- //k--;
- sort(v.begin(), v.end());
- vector<int> bruh;
- vector<long double> prob, ps;
- bruh.push_back(v[0].first);
- ps.push_back(v[0].second);
- prob.push_back(v[0].first * v[0].second);
- for(int i = 1; i < n; i++) {
- ps.push_back(ps[i - 1] + v[i].second);
- prob.push_back(prob[i - 1] + (v[i].first * v[i].second));
- bruh.push_back(v[i].first);
- }
- while(k--) {
- long double _ = 0;
- int qnt = lower_bound(bruh.begin(), bruh.end(), ss) - bruh.begin();
- _ += ss * ps[qnt - 1] + (prob[n - 1] - prob[qnt - 1]);
- ss = _;
- }
- cout << ss << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement