QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#442476#8524. Weather Forecastucup-team2010#WA 0ms4056kbC++20985b2024-06-15 12:19:152024-06-15 12:19:16

Judging History

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

  • [2024-06-15 12:19:16]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4056kb
  • [2024-06-15 12:19:15]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;

bool check(const std::vector<int>& a, int n, int k, double mid) {
    std::vector<double> adj(n);
    for (int i = 0; i < n; ++i) {
        adj[i] = a[i] - mid;
    }

    double sum = 0;
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        sum += adj[i];
        if (sum >= 0) {
            cnt++;
            sum = 0;
        }
    }

    return cnt >= k;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n, k;
    std::cin >> n >> k;

    std::vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        std::cin >> a[i];
    }

    double lo = 1.0, hi = 1000.0;
    while (hi - lo > 1e-9) {
        double mid = lo + (hi - lo) / 2;
        if (check(a, n, k, mid)) {
            lo = mid + 1e-9;
        } else {
            hi = mid - 1e-9;
        }
    }

    std::cout << std::fixed << std::setprecision(9) << lo;

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

7 3
1 3 1 2 2 2 1

output:

1.666666667

result:

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

Test #2:

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

input:

1 1
1

output:

1.000000000

result:

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

Test #3:

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

input:

2 1
2 1

output:

2.000000000

result:

wrong answer 1st numbers differ - expected: '1.50000', found: '2.00000', error = '0.50000'