Submission #1042888

#TimeUsernameProblemLanguageResultExecution timeMemory
1042888LOLOLOLet's Win the Election (JOI22_ho_t3)C++14
11 / 100
131 ms4460 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define f first #define s second #define pb push_back #define ep emplace #define eb emplace_back #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin()) #define mem(f,x) memset(f , x , sizeof(f)) #define sz(x) (ll)(x).size() #define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b)) #define mxx *max_element #define mnn *min_element #define cntbit(x) __builtin_popcountll(x) #define len(x) (int)(x.length()) const int N = 500 + 10; double a[N], b[N]; double f[N][N], cost[N][N]; int order[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i] >> b[i]; if (b[i] < 0) b[i] = 1e9; order[i] = i; } sort(order + 1, order + 1 + n, [&] (int x, int y) {return b[x] < b[y];}); vector <double> lst; for (int i = n; i >= 1; i--) { lst.pb(a[order[i]]); sort(all(lst)); double sum = 0; cost[i][0] = 0; for (int j = 0; j < sz(lst); j++) { sum += lst[j]; cost[i][j + 1] = sum; } } double ans = 1e9; for (int num = 0; num < k; num++) { for (int i = 0; i <= k; i++) { for (int j = 0; j <= k; j++) f[i][j] = 1e9; } f[0][0] = 0; for (int i = 1; i <= k; i++) { for (int j = 0; j <= i; j++) { f[i][j] = f[i - 1][j] + a[order[i]] / double(num + 1); if (j > 0) { f[i][j] = min(f[i][j], f[i - 1][j - 1] + b[order[i]] / double(j)); } if (j == num) { int r = k - i; ans = min(ans, f[i][j] + cost[i + 1][r] / double(num + 1)); } } } } 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...