Submission #894320

#TimeUsernameProblemLanguageResultExecution timeMemory
894320juliany2Let's Win the Election (JOI22_ho_t3)C++17
100 / 100
179 ms2644 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; #define all(x) (x).begin(), (x).end() const int N = 507; int n, k; array<int, 2> a[N]; double dp[N][N]; int main() { cin.tie(0)->sync_with_stdio(false); cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i][0] >> a[i][1]; if (a[i][1] == -1) a[i][1] = 1e9; } sort(a + 1, a + n + 1, [&](array<int, 2> &x, array<int, 2> &y) { return x[1] < y[1]; }); double ans = 1e9; for (int c = 0; c <= k; c++) { for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) dp[i][j] = 1e9; dp[0][0] = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j < i; j++) { if (j < k - c) dp[i][j + 1] = min(dp[i][j + 1], dp[i - 1][j] + (double) a[i][0] / (c + 1)); if (i - j - 1 < c && a[i][1] < 1e9) dp[i][j] = min(dp[i][j], dp[i - 1][j] + (double) a[i][1] / (i - j)); if (i - j - 1 >= c) dp[i][j] = min(dp[i][j], dp[i - 1][j]); } } ans = min(ans, dp[n][k - c]); } cout << fixed << setprecision(10) << ans << '\n'; return 0; }
#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...