QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#665675#8037. Gambler's RuincrychicWA 1ms5860kbC++171.6kb2024-10-22 14:42:102024-10-22 14:42:34

Judging History

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

  • [2024-10-22 14:42:34]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5860kb
  • [2024-10-22 14:42:10]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
 
using ll = long long; using ull = unsigned long long; using pii = pair<int, int>;
 
template <typename A, typename B> bool smax(A &a, const B &b) { return a < b ? a = b, 1 : 0; }
template <typename A, typename B> bool smin(A &a, const B &b) { return b < a ? a = b, 1 : 0; }
 
constexpr int N = 1e6 + 7;
constexpr double eps = 1e-10;
 
int n;
pair<double, ll> a[N];
ll pres[N], sufs[N];
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i].first >> a[i].second;
 
    sort(a + 1, a + n + 1, greater<pair<double, int>>());
    int cnt = 0;
    for (int i = 1; i <= n; ++i)
        if (i == 1 || a[i].first - a[i - 1].first > 0) a[++cnt] = a[i];
        else a[cnt].second += a[i].second;
    n = cnt;
    for (int i = 1; i <= n; ++i) pres[i] = pres[i - 1] + a[i].second;
    for (int i = n; i; --i) sufs[i] = sufs[i + 1] + a[i].second;
    
    double ans = 0;
    for (int i = 1, p = n; i <= n; ++i) if (i == n || a[i].first - a[i + 1].first > 0) {
        while (p > 1 && pres[i] / a[i].first > sufs[p] / (1 - a[p].first)) --p;
        smax(ans, pres[i] + sufs[p + 1] - pres[i] / a[i].first);
        // cout << ans << '\n';
        // if (i >= p) break;
        // cout << i << ' ' <<  p << '\n';
        if(p == 1 && pres[i]/a[i].first > sufs[p]/(1 - a[p].first)) continue;
        smax(ans, pres[i] + sufs[p] - sufs[p] / (1 - a[p].first));
        // cout << ans << '\n';
    }
    
    cout << fixed << setprecision(10) << ans << '\n';
    
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5860kb

input:

2
1 15
0 10

output:

0.0000000000

result:

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