Submission #1019238

#TimeUsernameProblemLanguageResultExecution timeMemory
1019238NurislamLet's Win the Election (JOI22_ho_t3)C++17
100 / 100
1881 ms4444 KiB
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define pb push_back #define ff first #define ss second #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define int long long #define double long double const int N = 1e6+5, inf = 1e9, mod = 1e9+7; template <class F, class _S> bool chmin(F &u, const _S &v){ bool flag = false; if ( u > v ){ u = v; flag |= true; } return flag; } template <class F, class _S> bool chmax(F &u, const _S &v){ bool flag = false; if ( u < v ){ u = v; flag |= true; } return flag; } double dp[505][505]; void solve(){ int n, k;cin >> n >> k; vector<pair<int,int> > v; for(int i = 0; i < n; i++){ int a, b; cin >> a >> b; if(b == -1)b = inf; v.pb({b, a}); } sort(all(v)); vector<int> a(n+1), b(n+1); for(int i = 1; i <= n; i++){ b[i] = v[i-1].ff; a[i] = v[i-1].ss; } vector<int> _a; for(int i = 1; i <= n; i++)_a.pb(a[i]); sort(all(_a)); double ans = 0; for(int i = 0; i < k; i++)ans+=_a[i]; for(int m = 1; m <= k; m++){ for(int i = 0; i <= n; i++) for(int j = 0; j <= n; j++)dp[i][j] = inf; dp[0][0] = 0; for(int i = 1; i <= k; i++){ for(int j = 0; j <= min(i, m); j++){ if(j && b[i] < inf)chmin(dp[i][j], dp[i-1][j-1] + (double)b[i]/(double)(j)); chmin(dp[i][j], dp[i-1][j] + (double)a[i]/(double)(m+1)); if(j==m){ vector<int> v; for(int q = i+1;q <= n; q++)v.pb(a[q]); sort(all(v)); int sum = 0; for(int q = 0; q < k-i; q++)sum += v[q]; chmin(ans, dp[i][j] + (double)sum / (double)(m+1)); } } } } cout << fixed << setprecision(15) << ans << '\n'; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int tt = 1; //cin >> tt; while(tt--){ solve(); } }
#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...