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<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include <cassert>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric> //gcd(a,b)
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<pii,int>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-loops")
using namespace std;
#define int long long
#define double long double
const int mod=998244353,mxn=2e5+5,lg=30,inf=1e18,minf=-1e18,Mxn=100000;
bool use[mxn+10];
int32_t main(){
fastio
int n,k;cin>>n>>k;
double ans=0;
vector<ppii>v(n);
for(int i=0;i<n;i++)cin>>v[i].f.f>>v[i].f.s,v[i].s=i;
vector<pii>b;
for(int i=0;i<n;i++)if(v[i].f.s!=-1)b.pb({v[i].f.s,i});
sort(all(b));
sort(all(v));
for(int i=0;i<k;i++)ans+=v[i].f.f;
double add=0;
for(int i=0;i<k&&i<b.size();i++){
use[b[i].s]=true;
add+=(b[i].f)*1.0/(i+1);
double sum=add*1.0;
int cnt=i+1;
for(int j=0;j<n&&cnt<k;j++){
if(use[v[j].s])continue;
sum+=(v[j].f.f*1.0)/(i+2);
cnt++;
}
if(cnt==k)ans=min(ans,sum);
}
cout<<setprecision(18);
cout<<ans;
}
Compilation message (stderr)
Main.cpp: In function 'int32_t main()':
Main.cpp:50:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(int i=0;i<k&&i<b.size();i++){
| ~^~~~~~~~~
# | 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... |