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],ans=1e100;
bool vis[N];
vector<pii>tog,need;
void solve(int val){
tog.clear();
need.clear();
memset(vis,0,sizeof(vis));
for (int i=0;i<n;i++){
if (val&(1LL<<i)){
need.push_back({a[i],i});
if (b[i]!=-1){
tog.push_back({b[i],i});
}
// cout<<1;
}
// cout<<0;
}
// cout<<'\n';
sort(need.begin(),need.end());
sort(tog.begin(),tog.end());
for (int i=0;i<=tog.size();i++){
dp[i]=0;
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 tans=1e100;
for (int i=0;i<=tog.size();i++){
tans=min(tans,dp[i]);
}
// cout<<" -> "<<tans<<'\n';
ans=min(ans,tans);
}
signed main(){
fast
cout<<fixed<<setprecision(2);
cin>>n>>k;
for (int i=0;i<n;i++){
cin>>a[i]>>b[i];
}
for (int i=1;i<(1LL<<n);i++){
int cnt=0;
for (int j=0;j<n;j++){
if (i&(1LL<<j)) cnt++;
}
if (cnt==k) solve(i);
}
cout<<ans<<'\n';
}
Compilation message (stderr)
Main.cpp: In function 'void solve(long long int)':
Main.cpp:38: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]
38 | for (int i=0;i<=tog.size();i++){
| ~^~~~~~~~~~~~
Main.cpp:41: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]
41 | for (int j=0;j<i&&j<tog.size();j++){
| ~^~~~~~~~~~~
Main.cpp:55: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]
55 | for (int i=0;i<=tog.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... |