Submission #879953

#TimeUsernameProblemLanguageResultExecution timeMemory
879953frostray8653Let's Win the Election (JOI22_ho_t3)C++17
10 / 100
275 ms4748 KiB
#include <bits/stdc++.h> #define int long long #define IO ios::sync_with_stdio(0), cin.tie(0) #define FOR(i, a, b) for (int i = a; i <= b; i++) using namespace std; using pii = pair<int, int>; const int N = 505; const int INF = 1e9; const double dINF = 1e9; pii a[N]; signed main() { IO; int n, tar; cin >> n >> tar; FOR(i, 1, n) { cin >> a[i].first >> a[i].second; if (a[i].second == -1) a[i].second = INF; } sort(a + 1, a + n + 1, [&](pii p, pii q) { return p.second < q.second; }); vector<vector<double>> dp(n + 1, vector<double>(n + 1, dINF)); dp[0][0] = 0; for (int i = 1; i <= n; i++) { vector<vector<double>> ndp(n + 1, vector<double>(n + 1, dINF)); for (int j = 0; j < i; j++) { for (int k = 0; k <= j; k++) { if (dp[j][k] < dINF) { ndp[j][k] = min(ndp[j][k], dp[j][k]); if (a[i].second < INF) ndp[j + 1][k + 1] = min(ndp[j + 1][k + 1], dp[j][k] + (double)a[i].second / (k + 1)); ndp[j + 1][k] = min(ndp[j + 1][k], dp[j][k] + (double)a[i].first / (k + 1)); } } } swap(dp, ndp); } double ans = dINF; for (int k = 0; k <= n; k++) ans = min(ans, dp[tar][k]); cout << fixed << setprecision(15) << 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...