Submission #528915

#TimeUsernameProblemLanguageResultExecution timeMemory
528915FireGhost1301Let's Win the Election (JOI22_ho_t3)C++11
100 / 100
261 ms2396 KiB
#include <bits/stdc++.h> using namespace std; const int N = 500 + 3; const double inf = 1e6 + 3; int n, k, a[N], b[N], p[N]; double f[N][N]; double calc(int m) { for (int i = 1; i <= n; ++i) { for (int j = 0; j <= i; ++j) { f[i][j] = inf; if (j) f[i][j] = min(f[i][j], f[i - 1][j - 1] + (double)a[p[i]] / (m + 1)); if (j < i) { if (i - j - 1 < m) f[i][j] = min(f[i][j], f[i - 1][j] + (double)b[p[i]] / (i - j)); else f[i][j] = min(f[i][j], f[i - 1][j]); } } } return f[n][k - m]; } void solve() { cin >> n >> k; for (int i = 1; i <= n; ++i) { cin >> a[i] >> b[i]; if (b[i] == -1) b[i] = INT_MAX; } iota(p + 1, p + n + 1, 1); sort(p + 1, p + n + 1, [&](int i, int j) { if (b[i] != b[j]) return b[i] < b[j]; return a[i] < a[j]; }); double ans = inf; for (int i = 0; i <= k; ++i) ans = min(ans, calc(i)); cout << ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout << setprecision(15) << fixed; solve(); 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...