QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#642108#8524. Weather ForecastGrand_ElfWA 1ms9860kbC++171.2kb2024-10-15 10:22:502024-10-15 10:22:52

Judging History

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

  • [2024-10-15 10:22:52]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:9860kb
  • [2024-10-15 10:22:50]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 5;
const double eps = 1e-5;

int n, k, f[N], id[N], rk[N], mx[N];
double a[N], sum[N], b[N];

bool cmp(int i, int j) {
	return b[i] < b[j];
}

void add(int x, int v) {
	for (; x <= n + 1; x += x & -x) {
		mx[x] = max(mx[x], v);
	}
}

int query(int x) {
	int res = -0x3f3f3f3f;
	for (; x; x -= x & -x) {
		res = max(res, mx[x]);
	}
	return res;
}

bool check(double mid) {
	for (int i = 0; i <= n; i++) {
		b[i] = sum[i] - i * mid;
		id[i] = i;
		mx[i] = -0x3f3f3f3f;
	}
	sort(id, id + n + 1, cmp);
	for (int i = 0; i <= n; i++) {
		rk[id[i]] = i + 1;
	}
	f[0] = 0;
	add(rk[0], f[0]);
	for (int i = 1; i <= n; i++) {
		f[i] = query(rk[i]) + 1;
		if (f[i] >= 0) {
			add(rk[i], f[i]);
		}
	}
	return f[n] >= k;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		sum[i] = sum[i - 1] + a[i];
	}
	double l = 1, r = 1000;
	while (r - l > eps) {
		double mid = (l + r) / 2;
		if (check(mid)) {
			l = mid;
		} else {
			r = mid;
		}
	}
	cout << fixed << setprecision(5) << l << '\n';

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

7 3
1 3 1 2 2 2 1

output:

1.66667

result:

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

Test #2:

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

input:

1 1
1

output:

1.00000

result:

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

Test #3:

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

input:

2 1
2 1

output:

1.50000

result:

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

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 9860kb

input:

3 2
2 4 4

output:

3.33333

result:

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