#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
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 |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
348 KB |
Output is correct |
7 |
Correct |
7 ms |
480 KB |
Output is correct |
8 |
Correct |
7 ms |
344 KB |
Output is correct |
9 |
Correct |
7 ms |
480 KB |
Output is correct |
10 |
Correct |
7 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
348 KB |
Output is correct |
7 |
Correct |
7 ms |
480 KB |
Output is correct |
8 |
Correct |
7 ms |
344 KB |
Output is correct |
9 |
Correct |
7 ms |
480 KB |
Output is correct |
10 |
Correct |
7 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Execution timed out |
2528 ms |
472 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
4 ms |
348 KB |
Output is correct |
17 |
Correct |
94 ms |
348 KB |
Output is correct |
18 |
Correct |
28 ms |
592 KB |
Output is correct |
19 |
Correct |
218 ms |
440 KB |
Output is correct |
20 |
Correct |
35 ms |
348 KB |
Output is correct |
21 |
Correct |
32 ms |
348 KB |
Output is correct |
22 |
Correct |
222 ms |
448 KB |
Output is correct |
23 |
Correct |
35 ms |
344 KB |
Output is correct |
24 |
Correct |
11 ms |
344 KB |
Output is correct |
25 |
Correct |
252 ms |
348 KB |
Output is correct |
26 |
Correct |
117 ms |
436 KB |
Output is correct |
27 |
Correct |
225 ms |
436 KB |
Output is correct |
28 |
Correct |
214 ms |
348 KB |
Output is correct |
29 |
Correct |
223 ms |
348 KB |
Output is correct |
30 |
Correct |
234 ms |
436 KB |
Output is correct |
31 |
Correct |
215 ms |
444 KB |
Output is correct |
32 |
Correct |
221 ms |
440 KB |
Output is correct |
33 |
Correct |
217 ms |
348 KB |
Output is correct |
34 |
Correct |
218 ms |
344 KB |
Output is correct |
35 |
Correct |
221 ms |
596 KB |
Output is correct |
36 |
Correct |
224 ms |
692 KB |
Output is correct |
37 |
Correct |
216 ms |
348 KB |
Output is correct |
38 |
Correct |
206 ms |
596 KB |
Output is correct |
39 |
Correct |
235 ms |
348 KB |
Output is correct |
40 |
Correct |
214 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
4 ms |
348 KB |
Output is correct |
17 |
Correct |
94 ms |
348 KB |
Output is correct |
18 |
Correct |
28 ms |
592 KB |
Output is correct |
19 |
Correct |
218 ms |
440 KB |
Output is correct |
20 |
Correct |
35 ms |
348 KB |
Output is correct |
21 |
Correct |
32 ms |
348 KB |
Output is correct |
22 |
Correct |
222 ms |
448 KB |
Output is correct |
23 |
Correct |
35 ms |
344 KB |
Output is correct |
24 |
Correct |
11 ms |
344 KB |
Output is correct |
25 |
Correct |
252 ms |
348 KB |
Output is correct |
26 |
Correct |
117 ms |
436 KB |
Output is correct |
27 |
Correct |
225 ms |
436 KB |
Output is correct |
28 |
Correct |
214 ms |
348 KB |
Output is correct |
29 |
Correct |
223 ms |
348 KB |
Output is correct |
30 |
Correct |
234 ms |
436 KB |
Output is correct |
31 |
Correct |
215 ms |
444 KB |
Output is correct |
32 |
Correct |
221 ms |
440 KB |
Output is correct |
33 |
Correct |
217 ms |
348 KB |
Output is correct |
34 |
Correct |
218 ms |
344 KB |
Output is correct |
35 |
Correct |
221 ms |
596 KB |
Output is correct |
36 |
Correct |
224 ms |
692 KB |
Output is correct |
37 |
Correct |
216 ms |
348 KB |
Output is correct |
38 |
Correct |
206 ms |
596 KB |
Output is correct |
39 |
Correct |
235 ms |
348 KB |
Output is correct |
40 |
Correct |
214 ms |
348 KB |
Output is correct |
41 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
42 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2547 ms |
464 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
348 KB |
Output is correct |
7 |
Correct |
7 ms |
480 KB |
Output is correct |
8 |
Correct |
7 ms |
344 KB |
Output is correct |
9 |
Correct |
7 ms |
480 KB |
Output is correct |
10 |
Correct |
7 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Execution timed out |
2528 ms |
472 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |