제출 #526833

#제출 시각아이디문제언어결과실행 시간메모리
526833abc864197532Let's Win the Election (JOI22_ho_t3)C++17
100 / 100
299 ms328 KiB
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T i, U ...j) {
	cout << i << ' ', abc(j...);
}
template <typename T> void printv(T l, T r) {
	for (; l != r; ++l) cout << *l << " \n"[l + 1 == r];
}
#ifdef Doludu
#define test(x...) abc("[" + string(#x) + "]", x)
#define owo freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#else
#define test(x...) void(0)
#define owo ios::sync_with_stdio(false), cin.tie(0);
#endif
const int N = 200000;

int main () {
	owo;
	int n, k;
	cin >> n >> k;
	vector <pii> state(n);
	for (int i = 0; i < n; ++i) {
		cin >> state[i].X >> state[i].Y;
		if (state[i].Y == -1)
			state[i].Y = 1 << 30;
	}
	/*
	 let number of choose B be x
	 B[i] / 1 + B[i] / 2 + ... + B[i] / x + A[i] / (x + 1) + A[i] / (x + 1) + ...
	 dp[i][j][k] -> consider first i state, choose j for B, k for C the min answer
	 */
	sort(all(state), [&](pii i, pii j) {
		if (i.Y == j.Y)
			return i.X < j.X;
		return i.Y < j.Y;
	});
	double ans = 1e9;
	for (int x = 0; x <= k; ++x) {
		vector <double> dp(n + 1, 1e9);
		dp[0] = 0;
		for (int i = 0; i < n; ++i) {
			vector <double> nxt(n + 1, 1e9);
			for (int j = 0; j <= i + 1; ++j) {
				if (j) 
					nxt[j] = min(nxt[j], dp[j - 1] + double(state[i].X) / (x + 1));
				if (i + 1 - j <= x)
					nxt[j] = min(nxt[j], dp[j] + double(state[i].Y) / (i + 1 - j));
				else
					nxt[j] = min(nxt[j], dp[j]);
			}
			dp = nxt;
		}
		ans = min(ans, dp[k - x]);
	}
	cout << fixed << setprecision(10) << ans << endl;
}
#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...