Submission #1278140

#TimeUsernameProblemLanguageResultExecution timeMemory
1278140nanaseyuzukiLet's Win the Election (JOI22_ho_t3)C++20
10 / 100
628 ms994648 KiB
#include <bits/stdc++.h>
// Author: Kazuki_Will_Win_VOI_8703
#define fi first
#define se second
#define pii pair<int, int>
#define ll long long
using namespace std;

const int mn = 5e2 + 5, lg2 = 20, mbit = (1 << 20) + 1, mm = 5e3 + 5;
const double inf = 1e36;

int n, K;

struct Megumi{
	int a, b;
	bool operator<(const Megumi& other) const{
		if(b == other.b) return a < other.a;
		return b < other.b;
	}
} e[mn];

double dp[mn][mn][mn];

void solve(){
	cin >> n >> K;
	for(int i = 1; i <= n; i++){
		cin >> e[i].a >> e[i].b;
		e[i].b = (e[i].b == -1 ? inf : e[i].b);
	}
	sort(e + 1, e + n + 1);
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= K; j++){
			for(int k = 0; k <= K; k++){
			   dp[i][j][k] = inf;
			}
		}
	}
	dp[0][1][0] = 0;
	double ans = inf;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= K; j++){
			for(int k = j - 1; k <= K; k++){
				dp[i][j][k] = min({dp[i - 1][j - 1][k - 1] + (double) e[i].b / (double) (j - 1),
								dp[i - 1][j][k - 1] + (double) e[i].a / (double) j,
								dp[i - 1][j][k]});
				if(k == K){
					ans = min(ans, dp[i][j][k]);
				}
			}
		}
	}
	cout << setprecision(15) << fixed << ans << '\n';
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    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...