QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#728686#8037. Gambler's RuindreamwaveWA 0ms3980kbC++141.6kb2024-11-09 15:39:492024-11-09 15:39:51

Judging History

你现在查看的是最新测评结果

  • [2024-11-09 15:39:51]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3980kb
  • [2024-11-09 15:39:49]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define double long double

const double eps = 1e-10;

void solve() {
    int n;
    std::cin >> n;
    std::vector < std::pair < double , int > > a(n);
    for(auto &[x, y] : a) std::cin >> x >> y;
    std::vector < std::pair < double , int > > used;
    std::sort(a.begin(), a.end());
    used.emplace_back(0, 0);
    for(int i = 0; i < a.size(); ++i) {
        if(used.size() == 1) {
            used.emplace_back(a[i]);
            continue;
        }
        if(fabs(used.back().first - a[i].first) < eps) {
            used.back().second += a[i].second;
        } else {
            used.emplace_back(a[i]);
        }
    }
    int len = used.size() - 1;
    std::vector < int > sum(len + 1);
    for(int i = 1; i <= len; ++i) {
        sum[i] = sum[i - 1] + used[i].second;
        // std::cout << used[i].first << ' ' << used[i].second << '\n';
    }
    double ans = 0;
    for(int r = len, l = 1; r >= 1; --r) {
        // if(used[r].first == 0) continue;
        double now = (sum[n] - sum[r - 1]) / used[r].first;
        while(l < r && sum[l] / (1 - used[l].first) < now) ++l;
        ans = std::max(ans, 1.0 * (sum[n] - sum[r - 1]) + 1.0 * sum[l - 1] - now);
        if(l >= r) break;
        ans = std::max(ans, 1.0 * (sum[n] - sum[r - 1]) + 1.0 * sum[l] - 1.0 * sum[l] / (1.0 - used[l].first));
    }
    std::cout << std::fixed << std::setprecision(10) << ans << '\n';
}

signed main() {
    std::cin.tie(nullptr) -> sync_with_stdio(false);
    int T = 1;
    while(T--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3940kb

input:

2
1 15
0 10

output:

10.0000000000

result:

ok found '10.0000000', expected '10.0000000', error '0.0000000'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3920kb

input:

3
0.4 100
0.5 100
0.6 100

output:

33.3333333333

result:

ok found '33.3333333', expected '33.3333333', error '0.0000000'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3756kb

input:

1
0 1

output:

0.0000000000

result:

ok found '0.0000000', expected '0.0000000', error '-0.0000000'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3824kb

input:

2
1 0
1 100

output:

0.0000000000

result:

ok found '0.0000000', expected '0.0000000', error '-0.0000000'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3812kb

input:

1
0.5 100

output:

0.0000000000

result:

ok found '0.0000000', expected '0.0000000', error '-0.0000000'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3920kb

input:

3
0.4 100
0.6 100
0.6 100

output:

0.0000000000

result:

ok found '0.0000000', expected '0.0000000', error '-0.0000000'

Test #7:

score: -100
Wrong Answer
time: 0ms
memory: 3980kb

input:

3
0.2 100
0.2 100
0.8 100

output:

0.0000000000

result:

wrong answer 1st numbers differ - expected: '50.0000000', found: '0.0000000', error = '1.0000000'