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;
typedef long long ll;
typedef long double ld;
#define S second
#define F first
#define all(x) (x).begin(),(x).end()
#define sz size()
#define Yes cout << "YES" << endl
#define No cout << "NO" << endl
#define pb(x) push_back(x);
#define endl '\n'
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int N=3e5+7;
ll INF=INT_MAX,mod=1e9+7;
int TT=1;
ll power(ll x, unsigned int y)
{
ll res = 1;
x = x; // % mod;
if (x == 0) return 0;
while (y > 0)
{
if (y & 1) res = (res*x) ; // % mod;
y = y>>1;
x = (x*x) ; // % mod;
}
return res;
}
ll n , k;
pair<ll,ll> a[N];
vector<ll> v;
vector<ll> v2;
bool cmp(pair<ll,ll> x , pair<ll,ll> y)
{
return x.S < y.S;
}
void solve()
{
cin >> n >> k;
for(int i = 1; i <= n ;i++) cin >> a[i].F >> a[i].S;
// sort(a+1,a+1+n,cmp);
ld allmn = 1e18;
for(int mask = 0; mask < (1<<n); mask++)
{
v.clear(); v2.clear();
if(__builtin_popcount(mask)>k) continue;
// cout << mask << ": " << endl;
bool notgood = 0;
for(int bit = 0; bit < n; bit++)
{
bool cur = (mask>>bit)&1;
//cout << cur;
if(cur==1&&a[bit+1].S==-1) {notgood = 1; break;}
if(cur==1)
{
v2.push_back(a[bit+1].S);
}
else
{
v.push_back(a[bit+1].F);
}
}
// cout << endl;
if(notgood==1) continue;
sort(all(v));
sort(all(v2));
ld num = 1;
ld cursum = 0;
for(int i = 0; i < v2.sz; i++) {cursum+= v2[i]/num/1.0; num++;}
for(int i = 0; i < k-__builtin_popcount(mask); i++) cursum += v[i]/(num)/1.0;
allmn = min(allmn,cursum);
// cout << cursum << endl;
}
cout << fixed << setprecision(10) << allmn << endl;
}
int main(){
//freopen("friday.in","r",stdin);
//freopen("friday.out","w",stdout);
fast;
// cin >> TT;
while(TT--)
solve();
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'void solve()':
Main.cpp:72:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for(int i = 0; i < v2.sz; i++) {cursum+= v2[i]/num/1.0; num++;}
| ^
# | 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... |