Submission #1043414

#TimeUsernameProblemLanguageResultExecution timeMemory
1043414LucppLet's Win the Election (JOI22_ho_t3)C++17
56 / 100
2543 ms1056 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define sz(x) (int)size(x) #define all(x) (x).begin(), (x).end() constexpr double inf = 1e18; double pmin(double &a, double b){ return a = min(a, b); } int main(){ cin.tie(0)->sync_with_stdio(false); int n, k; cin >> n >> k; vector<double> a(n), b(n); for(int i = 0; i < n; i++) cin >> a[i] >> b[i]; { vector<int> ord(n); for(int i = 0; i < n; i++) ord[i] = i; sort(all(ord), [&](int i, int j){return b[i] < b[j];}); vector<double> a2(n), b2(n); for(int i = 0; i < n; i++) a2[i] = a[ord[i]], b2[i] = b[ord[i]]; a = a2, b = b2; } double ans = inf; for(int l = 0; l <= k; l++){ vector<vector<double>> dp(l+1, vector<double>(k-l+1, inf)); dp[0][0] = 0; for(int i = 0; i < n; i++){ auto dp2 = dp; for(int j = 0; j <= l; j++){ for(int h = 0; h <= k-l; h++){ if(j < l && b[i] > 0) pmin(dp2[j+1][h], dp[j][h] + b[i] / (1+j)); if(h < k-l) pmin(dp2[j][h+1], dp[j][h] + a[i] / (1+l)); } } swap(dp, dp2); } ans = min(ans, dp[l][k-l]); } cout << setprecision(6) << fixed << ans << "\n"; }
#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...