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 ldb long double
#define fi first
#define se second
#define sza(a) (int)a.size()
#define pir pair<int,int>
#define pirll pair<ll,ll>
using namespace std;
const int maxn = 5e2 + 5;
const ll inf = 1e17;
void minimize(ldb &x,ldb y){
x = min(x,y);
}
pair <ldb,ldb> a[maxn];
bool cmp(pair <ldb,ldb> x,pair <ldb,ldb> y){
return (x.se < y.se);
}
void input(int n){
for (int i = 1 ; i <= n ; i++){
cin >> a[i].fi >> a[i].se;
if (a[i].se == -1) a[i].se = inf;
}
sort(a + 1,a + 1 + n,cmp);
}
ldb solve(int n,int k,int collab){
ldb res = 0;
int cnt = 1;
for (int i = 1 ; i <= collab ; i++){
if (a[i].se == inf) return inf;
res += a[i].se/(ldb)cnt;
cnt++;
}
if (collab == k) return res;
vector <ldb> lst;
for (int i = collab + 1 ; i <= n ; i++)
lst.push_back(a[i].fi);
sort(lst.begin(),lst.end());
for (int i = 0 ; i < k - collab ; i++)
res += lst[i]/(ldb)cnt;
return res;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
// freopen("ELECTION.inp","r",stdin);
// freopen("ELECTION.out","w",stdout);
int n,k;
cin >> n >> k;
input(n);
ldb res = inf;
for (int collab = 0 ; collab <= k ; collab++)
res = min(res,solve(n,k,collab));
cout << fixed << setprecision(10) << res;
return 0;
}
# | 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... |