Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define all(x) begin(x),end(x)
- using namespace std;
- using ld = long double;
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- ld n, s;
- cin >> n >> s;
- ld ans = 0;
- vector<pair<ld,ld>> arr;
- for (int i = 0; i < n; i++) {
- ld a, b, c;
- cin >> a >> b >> c;
- if (c > 0) {
- ans += c;
- if (b > 0) {
- arr.push_back({a, b});
- }
- }
- }
- n = arr.size();
- ld mn_val = 0;
- for (auto& [x, y] : arr) {
- if (x == 0) {
- mn_val = max(mn_val, y);
- }
- }
- ld left = mn_val;
- ld right = 1e9;
- ld mid;
- ld add = 0;
- for (int itr = 0; itr < 500; itr++) {
- mid = (left + right) / 2;
- ld used = 0;
- ld getted = 0;
- for (int i = 0; i < n; i++) {
- auto [a, b] = arr[i];
- // b + 2ax == mid
- // x = (mid - b) / (2a);
- if (a == 0) {
- continue;
- } else {
- ld x = (mid - b) / (2 * a);
- x = min(x, ld(-1) * b / 2 / a);
- if (x >= 0) {
- getted += a * x * x + b * x;
- used += x;
- }
- }
- }
- if (used <= s && mn_val > 0) {
- getted += mn_val * (s - used);
- }
- if (used <= s) {
- add = max(add, getted);
- }
- if (used > s) {
- left = mid;
- } else {
- right = mid;
- }
- }
- ans += add;
- cout << fixed << setprecision(15) << ans << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement