# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
658851 | Darren0724 | Let's Win the Election (JOI22_ho_t3) | C++17 | 424 ms | 2500 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>
using namespace std;
#define all(x) x.begin(),x.end()
#define int long long
int INF=1e9;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;cin>>n;
int k;cin>>k;
vector<pair<int,int>> v(n+1);
for(int i=1;i<=n;i++){
cin>>v[i].first>>v[i].second;
if(v[i].second==-1){
v[i].second=INF;
}
}
sort(all(v),[&](pair<int,int> a,pair<int,int> b){
return a.second<b.second;
});
double ans=INF;
for(int t=0;t<k;t++){
vector<vector<double>> dp(t+1,vector<double>(n+1,INF));
dp[0][0]=0;
for(int i=1;i<=n;i++){
dp[0][i]=dp[0][i-1]+(double)v[i].first/(t+1);
}
for(int i=1;i<=t;i++){
for(int j=1;j<=n;j++){
dp[i][j]=min(dp[i][j],dp[i-1][j-1]+(double)v[j].second/i);
dp[i][j]=min(dp[i][j],dp[i][j-1]+(double)v[j].first/(t+1));
}
}
double total=0;
double mn=INF;
priority_queue<double,vector<double>,greater<double>> pq;
for(int i=n;i>k;i--){
pq.push((double)v[i].first/(t+1));
}
for(int i=k;i>=t;i--){
mn=min(mn,dp[t][i]+total);
pq.push((double)v[i].first/(t+1));
while(pq.size()>n-k){
total+=pq.top();
pq.pop();
}
}
ans=min(ans,mn);
}
cout<<setprecision(9)<<ans<<endl;
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... |