Submission #1278144

#TimeUsernameProblemLanguageResultExecution timeMemory
1278144nanaseyuzukiLet's Win the Election (JOI22_ho_t3)C++20
Compilation error
0 ms0 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 = 1e100;

int n, K;

struct Megumi{
	int a, b;
	bool operator<(const Megumi& other) const{
		if(b == -1 && other.b != -1) return true;
		if(b != -1 && other.b == -1) return false;
		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;
	}
	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 = 0; k <= K; k++){
				dp[i][j][k] = dp[i - 1][j][k];
				if(k >= 1) dp[i][j][k] = min(dp[i][j][k], dp[i - 1][j][k - 1] + (double)e[i].a / (double)j);
				if(e[i].b != -1 && j >= 2 && k >= 1) dp[i][j][k] = min(dp[i - 1][j - 1][k - 1] + (double)e[i].b / (double)(j - 1), dp[i][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();
    }
}

Compilation message (stderr)

Main.cpp: In function 'void solve()':
Main.cpp:49:22: error: 'k' was not declared in this scope
   49 |                   if(k == K) ans = min(ans, dp[i][j][k]);
      |                      ^