# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
806593 | vjudge1 | Let's Win the Election (JOI22_ho_t3) | C++17 | 479 ms | 18524 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 TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define rall(s) s.rbegin(),s.rend()
#define all(s) s.begin(),s.end()
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ld long double
#define YES cout<<"YES\n"
#define Yes cout<<"Yes\n"
#define yes cout<<"yes\n"
#define NO cout<<"NO\n"
#define No cout<<"No\n"
#define no cout<<"no\n"
const int N = 500 + 9 , mod = 1e9 + 7;
ll d[N] = {} , a[N] = {}, b[N] , c[N];
ld dp[N][N];
ll sum[N][N];
multiset<pair<int,int>>st[N][N];
void del(int i , int j , int x , int y){
sum[i][j] -= x;
st[i][j].erase(st[i][j].find({x , y}));
}
void solve(){
ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn = 1e18 , mx = 0;
cin>>n>>k;
vector<pair<ll,ll>>v, v1;
multiset<ll>st;
v.pb({-5 , -5});
for(i = 1; i <= n; i++){
cin>>a[i]>>b[i];
if(b[i] == -1)
b[i] = 1e13;
v1.pb({a[i] , b[i]});
v.pb({b[i] , a[i]});
st.insert(a[i]);
}
sort(all(v));
sort(all(v1));
mn = 0;
for(i = 0; i < k; i++)
mn += v1[i].fi;
sum[0][0] = 0;
j = 1;
for(auto it : st)
sum[0][j] = sum[0][j - 1] + it ,j++;
for(i = 1; i <= n; i++){
st.erase(st.find(v[i].se));
sum[i][0] = 0;
j = 1;
for(auto it : st)
sum[i][j] = sum[i][j - 1] + it ,j++;
}
//cout<<mn<<"\n";
ld ans = mn;
for(x = 1; x <= k; x++){
for(i = 1; i <= x; i++)
dp[0][i] = 1e18;
for(i = 1; i <= k; i++){
for(j = 0; j <= x; j++){
if(j == 0){
dp[i][j] = dp[i - 1][j] + v[i].se / (ld) (x + 1);
continue;
}
dp[i][j] = dp[i - 1][j] + v[i].se / (ld) (x + 1);
dp[i][j] = min(dp[i][j] , dp[i - 1][j - 1] + v[i].fi / (ld) (j));
}
ans = min(ans , dp[i][x] + (sum[i][k - i]) / (ld) (x + 1));
}
}
cout<<fixed<<setprecision(12)<<ans<<"\n";
}
int main(){
TL;
/*
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
*/
int t = 1;
//cin>>t;
while(t--)
{
solve();
}
}
// Author : حسن
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... |