Submission #1283070

#TimeUsernameProblemLanguageResultExecution timeMemory
1283070thirdLet's Win the Election (JOI22_ho_t3)C++20
10 / 100
360 ms497560 KiB
#include<bits/stdc++.h>
typedef int ll;
#define pii pair<ll, ll>
#define fi first
#define se second
#define endl '\n'
#define TASK ""
#define N 503
#define LOG 17
using namespace std;

bool ghuy4g;

const ll inf = 1e9;

ll n, k;

pii a[N];

bool cmp(pii a, pii b) {
	return a.se < b.se;
}

double dp[N][N][N];

void minimize(double &X, double val) {
	if (X == 0) X = val;
	else {
		X = min(X, val);
	}
}

void sub3() {
	double ans = inf;
	dp[1][0][0] = 0;
	for (int i = 1; i <= n + 1; i ++) {
		for (int j = 0; j <= i - 1; j ++) {
			for (int cnt = 0; cnt <= j; cnt ++) {
				if (dp[i][j][cnt] == 0 && (i != 1 && j != 0 && cnt != 0)) {
					dp[i][j][cnt] = 1e9;
					continue;
				} 
				if (dp[i][j][cnt] == 1e9) continue;
				
				if (i == n + 1) {
					if (j >= k) ans = min(ans, dp[i][j][cnt]);
					continue;
				}
				
				// lam thang i -> A
				double nxt_x = dp[i][j][cnt] + double(a[i].fi) / (cnt + 1);
				minimize(dp[i + 1][j + 1][cnt], nxt_x);
				// lam den i -> B
				if (a[i].se != inf) {
					nxt_x = dp[i][j][cnt] + double(a[i].se) / (cnt + 1);
					minimize(dp[i + 1][j + 1][cnt + 1], nxt_x);
				}
				
				// ko lam gi
				minimize(dp[i + 1][j][cnt], dp[i][j][cnt]);
			}
		}
	}
	cout << fixed << setprecision(6) << ans;
}

bool klinh;

signed main() {
   // freopen("test.inp", "r", stdin);
	//freopen("test.out", "w", stdout);
	//srand(time(0));
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
   	cin >> n >> k;
   	for (int i = 1; i <= n; i ++) {
   		cin >> a[i].fi >> a[i].se;
   		if (a[i].se == -1) a[i].se = inf;
   	}
   	sort(a + 1, a + 1 + n, cmp);
   	
   	sub3();
   	
   	
   	cerr << fabs(&klinh - &ghuy4g) / double(1024 * 1024);
}






#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...