# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
554418 | Ronin13 | Let's Win the Election (JOI22_ho_t3) | C++14 | 399 ms | 2328 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ull unsigned ll
#define pb push_back
#define epb emplace_back
using namespace std;
const double inf = 1e9 + 1;
int main(){
int n; cin >> n;
int k; cin >> k;
pair<double, double> a[n + 1];
for(int i = 1; i <= n; i++){
cin >> a[i].s >> a[i].f;
if(a[i].f == -1) a[i].f = inf;
}
sort(a + 1, a + 1 + n);
for(int i = 1; i <= n; i++){
//cout << a[i].f << ' ' << a[i].s << "\n";
}
double ans = inf;
for(int x = 0; x <= n; x++){
double dp[n + 1][n + 1];
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 <= n; i++){
for(int j = 0; j <= n; j++){
if(j > 0)dp[i][j] =min(dp[i][j], dp[i - 1][j - 1] + a[i].f / j);
dp[i][j] = min(dp[i][j], dp[i - 1][j] + a[i].s / (x + 1));
}
}
double cursum = 0;
multiset <pair<double, int> > st;
for(int i = 1; i <= n; i++){
cursum += a[i].s;
st.insert({a[i].s, i});
}
while(st.size() > k) {
cursum -= st.rbegin() -> f;
st.erase(st.find(*st.rbegin()));
}
for(int i = 1; i <= n; i++){
double cur = dp[i - 1][x];
cur += cursum / (x + 1);
if(ans > cur){
//cout << dp[i - 1][x] << "\n";
//cout << x << ' ' << i;
//cout << "\n";
ans = cur;
}
multiset <pair<double, int> > :: iterator it = st.find({a[i].s, i});
if(it != st.end()){
cursum -= a[i].s;
st.erase({a[i].s, i});
}
if(st.size() > k - i && !st.empty()){
cursum -= st.rbegin() -> f;
st.erase(st.find(*st.rbegin()));
}
}
}
cout << fixed << setprecision(3) << ans;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |