Submission #1287180

#TimeUsernameProblemLanguageResultExecution timeMemory
1287180kaiboyLet's Win the Election (JOI22_ho_t3)C++20
10 / 100
81 ms472 KiB
#include <algorithm>
#include <iostream>

using namespace std;

const int   N = 500;
const int INF = 0x3f3f3f3f;

int aa[N], bb[N], ii[N];
int aa_[N], ss[N];
double dp[N + 1];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	int n, m; cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> aa[i] >> bb[i], ii[i] = i;
		if (bb[i] == -1)
			bb[i] = INF;
	}
	sort(ii, ii + n, [] (int i, int j) { return bb[i] < bb[j]; });
	for (int h = 0; h < m; h++) {
		int n_ = 0;
		for (int h_ = h; h_ < n; h_++)
			aa_[n_++] = aa[ii[h_]];
		sort(aa_, aa_ + n_);
		int s = 0;
		for (int z = 0; z < m - h; z++)
			s += aa_[z];
		ss[h] = s;
	}
	double ans = ss[0];
	for (int k_ = 1; k_ <= m; k_++) {
		for (int k = 0; k <= k_; k++)
			dp[k] = INF;
		dp[0] = 0;
		for (int h = 0; h < m; h++) {
			int i = ii[h], a = aa[i], b = bb[i];
			for (int k = k_; k >= 0; k--) {
				double x = dp[k] + (double) a / (k_ + 1);
				if (k && b != INF)
					x = min(x, dp[k - 1] + (double) b / k);
				dp[k] = x;
			}
			if (h + 1 < m)
				ans = min(ans, dp[k_] + (double) ss[h + 1] / (k_ + 1));
		}
	}
	printf("%.14f\n", ans);
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...