QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#442775 | #8524. Weather Forecast | ucup-team3678# | WA | 0ms | 3968kb | C++14 | 1.2kb | 2024-06-15 13:29:11 | 2024-06-15 13:29:14 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, a[N];
double f[N];
int val[N], g[N], mx[N];
void modify(int x, int y) {
for (; x <= n; x += x & -x) mx[x] = max(mx[x], y);
}
int query(int x) {
int res = 0;
for (; x; x -= x & -x) res = max(res, mx[x]);
return res;
}
signed main() {
int m; scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
double L = 1, R = 1000;
while (fabs(L - R) > 1e-6) {
double mid = (L + R) / 2;
vector< pair<double, int> > tp;
for (int i = 1; i <= n; ++i) {
f[i] = f[i - 1] + a[i] - mid;
tp.push_back(make_pair(f[i], i));
mx[i] = 0;
}
sort(tp.begin(), tp.end());
int cnt = 0;
for (auto [x, y] : tp) {
g[y] = 0, val[y] = ++cnt;
}
for (int i = 1; i <= n; ++i) if (f[i] > 0) {
g[i] = query(val[i]);
modify(val[i], g[i] + 1);
}
if (*max_element(g + 1, g + n + 1) >= m) {
L = mid;
} else {
R = mid;
}
}
printf("%.6lf\n", L);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3968kb
input:
7 3 1 3 1 2 2 2 1
output:
1.666666
result:
ok found '1.66667', expected '1.66667', error '0.00000'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
1 1 1
output:
1.000000
result:
ok found '1.00000', expected '1.00000', error '0.00000'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3884kb
input:
2 1 2 1
output:
1.000000
result:
wrong answer 1st numbers differ - expected: '1.50000', found: '1.00000', error = '0.50000'