This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("Ofast,unroll-loops,O3")
//#pragma GCC target("avx,avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,fma,tune=native")
#include<bits/stdc++.h>
//#include<bits/extc++.h>
//#pragma pack(1)
#define fast ios::sync_with_stdio(0); cin.tie(0);
#define int long long
#define pii pair<int,int>
#define x first
#define y second
#define N 515
using namespace std;
//using namespace __gnu_pbds;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//typedef tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> order_multiset;
//typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> order_set;
int n,k,a[N],b[N];
long double dp[N];
bool vis[N];
vector<pii>tog,need;
signed main(){
fast
cout<<fixed<<setprecision(20);
cin>>n>>k;
for (int i=1;i<=n;i++){
cin>>a[i]>>b[i];
need.push_back({a[i],i});
if (b[i]!=-1){
tog.push_back({b[i],i});
}
}
sort(need.begin(),need.end());
sort(tog.begin(),tog.end());
for (int i=0;i<=tog.size();i++){
int need_time=0,cnt=0;
for (int j=0;j<i&&j<tog.size();j++){
dp[i]+=((long double)tog[j].x/(j+1));
vis[tog[j].y]=1;
}
for (auto j:need){
if (!vis[j.y]){
cnt++;
need_time+=j.x;
}
if (cnt>=k-i) break;
}
dp[i]+=(long double)need_time/(i+1);
}
long double ans=1e100;
for (int i=0;i<=n;i++){
if (abs(dp[i])>0.00000001) ans=min(ans,dp[i]);
// cout<<dp[i]<<" ";
}
// cout<<'\n';
cout<<ans<<'\n';
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:34:16: 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]
34 | for (int i=0;i<=tog.size();i++){
| ~^~~~~~~~~~~~
Main.cpp:36:22: 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]
36 | for (int j=0;j<i&&j<tog.size();j++){
| ~^~~~~~~~~~~
# | 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... |