Submission #922069

#TimeUsernameProblemLanguageResultExecution timeMemory
922069cthbstLet's Win the Election (JOI22_ho_t3)C++14
10 / 100
1604 ms2644 KiB
#include <algorithm> #include <iomanip> #include <iostream> #include <utility> #include <vector> using namespace std; const int maxn = 505; const double INF = 1e18; int n, k; double a[maxn]; double b[maxn]; pair<double, double> p[maxn]; double dp[maxn][maxn]; double f(int s, int cnt) { vector<double> v; for (int i = s; i < n; i++) { v.push_back(a[i]); } if ((int)v.size() < cnt) return INF; sort(v.begin(), v.end()); double rtn = 0; for (int i = 0; i < cnt; i++) { rtn += v[i]; } return rtn; } double myDP(int x) { dp[0][0] = a[0] / (x + 1); dp[0][1] = b[0] / 1; for (int j = 2; j <= x; j++) dp[0][j] = INF; for (int i = 1; i < n; i++) { dp[i][0] = dp[i - 1][0] + a[i] / (x + 1); for (int j = 1; j <= x; j++) { if (j > i + 1) { dp[i][j] = INF; } else { double A = dp[i - 1][j] + a[i] / (x + 1); double B = dp[i - 1][j - 1] + b[i] / j; dp[i][j] = min(A, B); } } } double rtn = INF; for (int i = 0; i < n; i++) { rtn = min(rtn, dp[i][x] + f(i + 1, k - x) / (x + 1)); } // cout << "solve(" << x << ") = " << rtn << '\n'; return rtn; } int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; if (b[i] == -1) b[i] = INF; p[i] = {b[i], a[i]}; } sort(p, p + n); for (int i = 0; i < n; i++) { b[i] = p[i].first; a[i] = p[i].second; } double an = f(0, k); for (int x = 1; x <= k; x++) { an = min(an, myDP(x)); } cout << fixed << setprecision(15) << an << '\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...