https://i0.wp.com/eblogarithm.com/wp-content/uploads/2017/07/Codeforces-Round-409-rated-Div-2-based-on-VK-Cup-2017-Round-2-problem-C-Voltage-Keepsake-Solution-In-CC1.png?fit=640%2C360

Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2), problem: (C) Voltage Keepsake Solution In C/C++

#include <bits/stdc++.h>

using namespace std;

struct Time {
int i;
double v;
};

const int MAXN = 1e5;
int a[MAXN], b[MAXN];
Time t[MAXN+1];

int main() {
int n, p;
cin >> n >> p;
for (int i = 0; i < n; ++i) {
cin >> a[i] >> b[i];
t[i].v = 1. * b[i] / a[i];
t[i].i = i;
}
sort(t, t+n, [](Time const & a, Time const & b){ return a.v < b.v;});
t[n].v = 1e15;
double sum_a = 0, sum_b = 0, time;
cout.precision(10);
cout << fixed;
for (int i = 0; i < n; ++i) {
int j = t[i].i;
sum_a += a[j];
sum_b += b[j];
time = (1. * sum_b / (sum_a – p));
if(time < t[i+1].v && sum_a > p) {
cout << time;
return 0;
}
}
cout << -1;
}

(Visited 11 times, 1 visits today)



There are no comments

Add yours

Leave a Reply

%d bloggers like this: