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 ll long long
#define int ll
#define pii pair<int, int>
#define ff first
#define ss second
#define ld long double
#define pb push_back
pair<ld, ld> a[300100];
ll b[300100];
ll us[300100];
ll n, m;
bool cmp(int x, int y){
return a[x].ss < a[y].ss;
}
void solve(){
cin>>n>>m;
int cnt = 0;
vector<int> q;
for(int i=1; i<=n; i++){
cin>>a[i].ff>>a[i].ss;
if(a[i].ss == -1) a[i].ss = 1e9;
else cnt ++;
}
sort(a + 1, a + 1 + n);
for(int i=1; i<=n; i++){
if(a[i].ss != -1) q.pb(i);
}
//for(int i=1; i<=n; i++){
//cout<<a[i].ff<<' '<<a[i].ss<<'\n';
//}
sort(q.begin(), q.end(), cmp);
ld ans = 1e18;
for(int k=0; k<=n; k++){
q.clear();
for(int i=k + 1; i<=n; i++){
if(a[i].ss != 1e9) q.pb(i);
}
sort(q.begin(), q.end(), cmp);
for(int d=0; d<q.size(); d++){
ld res = 0;
for(int i=1; i<=n; i++) us[i] = 0;
for(int i=0; i<d; i++){
us[q[i]] = 1;
res += a[q[i]].ss / (i + 1);
}
ll g = d;
for(int i=1; g < m; i++){
if(!us[i]) res += a[i].ff / (d + 1), us[i] = 1, g ++;
}
//cout<<"##############\n";
//cout<<d<<' '<<res<<'\n';
//for(int i=0; i<d; i++){
////cout<<q[i]<<'\n';
//cout<<a[q[i]].ff<<' '<<a[q[i]].ss<<'\n';
//}
ans = min(ans, res);
}
}
cout<<fixed<<setprecision(9)<<ans<<'\n';
}
signed main(){
solve();
}
Compilation message (stderr)
Main.cpp: In function 'void solve()':
Main.cpp:45:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for(int d=0; d<q.size(); d++){
| ~^~~~~~~~~
# | 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... |