제출 #1264530

#제출 시각아이디문제언어결과실행 시간메모리
1264530kustov_vadim_533Let's Win the Election (JOI22_ho_t3)C++20
56 / 100
2599 ms142836 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

#define len(v) (int)((v).size())

const int inf = 1e9;

inline void solve(){
	ll n, k;
	cin >> n >> k;

	vector<pair<ll, ll>> a(n);
	for (int i = 0; i < n; ++i){
		cin >> a[i].first >> a[i].second;
	}

	sort(a.begin(), a.end(), [&](pair<int, int> p1, pair<int, int> p2){
		if (p1.second == -1 && p2.second == -1) return false;
		if (p1.second == -1 || p2.second == -1) return p1.second != -1;
		return p1.second < p2.second;
	});

	ld ans = 1e100;

	for (int l = 0; l <= n; ++l){
		vector<vector<vector<ld>>> dp(n + 1, vector<vector<ld>>(l + 1, vector<ld>(k + 1, 1e100)));
		dp[0][0][0] = 0;

		for (int i = 0; i < n; ++i){
			for (int j = 0; j <= l; ++j){
				for (int f = 0; f <= k; ++f){
					dp[i + 1][j][f] = dp[i][j][f];
				}
			}
			if (a[i].second != -1){
				for (int j = 0; j < l; ++j){
					for (int f = 0; f < k; ++f){
						dp[i + 1][j + 1][f + 1] = min(dp[i + 1][j + 1][f + 1], dp[i][j][f] + a[i].second / (ld)(j + 1));
					}
				}
			}
			for (int j = 0; j <= l; ++j){
				for (int f = 0; f < k; ++f){
					dp[i + 1][j][f + 1] = min(dp[i + 1][j][f + 1], dp[i][j][f] + a[i].first / (ld)(l + 1));
				}
			}
		}
		ans = min(ans, dp[n][l][k]);
	}
	cout << ans << '\n';
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout.precision(60);

	int t = 1;
//	cin >> t;

	while (t--) {
		solve();
	}
}
#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...