Submission #1175903

#TimeUsernameProblemLanguageResultExecution timeMemory
1175903TsaganaLet's Win the Election (JOI22_ho_t3)C++20
100 / 100
101 ms480 KiB
#include<bits/stdc++.h>

#define IOS ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define all(x) x.begin(), x.end()
#define int long long
#define pq priority_queue
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pp pop_back
#define F first
#define S second
#define ld double

using namespace std;

void solve () {
	int n, k;
	cin >> n >> k;
	vector<pair<ld, ld>> v(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i].S >> v[i].F;
		if (v[i].F == -1) v[i].F = 1e9;
	}
	sort(all(v));
	ld ans = 2e18;
	for (ld c = 0; c < k; c++) {
		int mx = k - c;
		vector<ld> dp(mx+1, 1e18);
		dp[0] = 0;
		for (int i = 0; i < n; i++) {
			for (int e = mx; e >= 0; e--) {
				if (e != mx) dp[e+1] = min(dp[e+1], dp[e] + v[i].S / (1.0 + c));
				int id = i + 1 - e;
				if (id <= 0) continue;
				if (id <= c) dp[e] += v[i].F / (ld)id;
			}
		}
		ans = min(ans, dp[mx]);
	}
	cout << fixed << setprecision(9) << ans << "\n";
}
signed main() {IOS solve(); 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...