QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#375432 | #8524. Weather Forecast | ucup-team1209# | WA | 2ms | 6708kb | C++20 | 1.8kb | 2024-04-03 10:39:45 | 2024-04-03 10:39:46 |
Judging History
answer
#include <bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;
cs int N = 2e5 + 5;
int n, k;
int a[N];
void cmx(int & x, int y) {
if(x < y) x = y;
}
int mx[N], m;
void add(int x, int v) {
++ x;
for(; x <= m; x += x & -x) cmx(mx[x], v);
}
int ask(int x) {
++ x;
int c = -1e9;
for(; x; x -= x & -x) cmx(c, mx[x]);
return c;
}
bool check(double C) {
static double b[N], c[N];
for(int i = 1; i <= n; i++) b[i] = a[i] - C;
for(int i = 1; i <= n; i++) b[i] += b[i - 1];
for(int i = 1; i <= n; i++) c[i] = b[i];
// cout << C << endl;
// for(int i = 1; i <= n; i++) cout << b[i] << ' '; cout << endl;
c[n + 1] = 0;
m = n + 1;
sort(c + 1, c + m + 1);
m = unique(c + 1, c + m + 1) - c - 1;
vector <int> f(n + 1, -1e9);
f[0] = 0;
memset(mx, -0x3f, sizeof mx);
add(lower_bound(c + 1, c + m + 1, 0) - c, 0);
// for(int i = 1; i <= m; i++) cout << c[i] << ' '; cout << endl;
// cout << lower_bound(c + 1, c + m + 1, 0) - c << endl;
for(int i = 1; i <= n; i++) {
b[i] = lower_bound(c + 1, c + m + 1, b[i]) - c;
f[i] = ask(b[i]) + 1;
add(b[i], f[i]);
// cout << b[i] << ' ' << f[i] << endl;
}
return f[n] >= k;
}
int main() {
#ifdef zqj
freopen("1.in","r",stdin);
#endif
ios :: sync_with_stdio(0), cin.tie(0);
cin >> n >> k;
double L = 1e4, R = 0;
for(int i = 1; i <= n; i++) {
cin >> a[i];
L = min(L, (double) a[i]);
R = max(R, (double) a[i]);
}
for(int T = 0; T <= 30; T++) {
double mid = (L + R) * 0.5;
if(check(mid)) L = mid;
else R = mid;
}
printf("%.10lf\n", L);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 6636kb
input:
7 3 1 3 1 2 2 2 1
output:
1.6666666660
result:
ok found '1.66667', expected '1.66667', error '0.00000'
Test #2:
score: 0
Accepted
time: 0ms
memory: 6708kb
input:
1 1 1
output:
1.0000000000
result:
ok found '1.00000', expected '1.00000', error '0.00000'
Test #3:
score: 0
Accepted
time: 2ms
memory: 6680kb
input:
2 1 2 1
output:
1.5000000000
result:
ok found '1.50000', expected '1.50000', error '0.00000'
Test #4:
score: 0
Accepted
time: 0ms
memory: 6700kb
input:
3 2 2 4 4
output:
2.9999999991
result:
ok found '3.00000', expected '3.00000', error '0.00000'
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 6428kb
input:
4 2 6 7 3 12
output:
5.9999999972
result:
wrong answer 1st numbers differ - expected: '6.50000', found: '6.00000', error = '0.50000'