QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#451420#8524. Weather ForecastHKOI0#WA 1ms3908kbC++201.3kb2024-06-23 11:43:162024-06-23 11:43:16

Judging History

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

  • [2024-06-23 11:43:16]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3908kb
  • [2024-06-23 11:43:16]
  • 提交

answer

#include <bits/stdc++.h>
#define sz(v) (int)v.size()
#define all(v) v.begin(), v.end()

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

bool can(int n, int k, vector<int>& a, double x){
    vector<double> s(n + 1);
    s[0] = 0; for (int i = 0; i < n; i++) s[i + 1] = s[i] + a[i] - x;
    vector<double> st {0};
    // cout << x << endl;
    // for (auto x : s) cout << x << ' '; cout << endl;
    for (int i = 1; i <= n; i++) {
        if (s[i] < 0) continue;
        int idx = upper_bound(st.begin(), st.end(), s[i]) - st.begin();
        if (idx == st.size()) st.push_back(s[i]);
        else st[idx] = s[i];
    }
    return upper_bound(st.begin(), st.end(), s[n]) - st.begin() >= k;
}


void solve() {
    int n, k; cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    double lo = 0, hi = 1e3;
    while (hi - lo > 1e-6) {
        double mid = (lo + hi) / 2;
        if (can(n, k, a, mid)) {
            lo = mid;
        } else {
            hi = mid;
        }
    }
    cout << fixed << setprecision(10) << lo << '\n';
}

signed main() {
#ifndef LOCAL
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#endif
    int T = 1;
    // cin >> T;
    while (T--) solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3816kb

input:

7 3
1 3 1 2 2 2 1

output:

1.6666660085

result:

ok found '1.66667', expected '1.66667', error '0.00000'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3908kb

input:

1 1
1

output:

0.9999992326

result:

ok found '1.00000', expected '1.00000', error '0.00000'

Test #3:

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

input:

2 1
2 1

output:

1.4999993145

result:

ok found '1.50000', expected '1.50000', error '0.00000'

Test #4:

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

input:

3 2
2 4 4

output:

3.3333329484

result:

wrong answer 1st numbers differ - expected: '3.00000', found: '3.33333', error = '0.33333'