#include <bits/stdc++.h>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define pii pair<int,int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define STL(i, x) for(auto &i:x) cout << i << " "; cout << "\n";
#define iNf 2147483647
using namespace std;
ostream& operator<<(ostream &os, pii XXX){
cout << "[" << XXX.ff << ", " << XXX.ss << "]";
}
void db(){
cout << "\n";
}
template<class T, class ...U>
void db(T XXX, U ...YYY){
cout << XXX; db(YYY...);
}
bool cmp(pii &XXX, pii &YYY){
return ((XXX.ff - YYY.ff) / 2 > (XXX.ss > YYY.ss));
}
bool cmp_ff(pii &XXX, pii &YYY){
return (XXX.ff != YYY.ff) ? (XXX.ff < YYY.ff) : (XXX.ss < YYY.ss);
}
bool cmp_ss(pii &XXX, pii &YYY){
return (XXX.ss != YYY.ss) ? (XXX.ss < YYY.ss) : (XXX.ff < YYY.ff);
}
int main(){
int n, k;
cin >> n >> k;
int a[505], b[505];
vector<pii> org(n), dp;
loop(i,0,n){
cin >> a[i] >> b[i];
if(b[i] == -1)
b[i] = iNf;
org[i] = mp(a[i], b[i]);
}
long double ans = (1e300), tmp_ans;
int tmp_get, tmp_now;
sort(org.begin(), org.end());
// STL(i, org);
loop(i,0,k+1){
dp = org;
tmp_ans = 0;
tmp_get = 0;
tmp_now = 1;
loop(j,0,i){
if(dp[j].ss == iNf) break;
tmp_ans += (long double)dp[j].ss / tmp_now;
dp[j].ff = iNf;
dp[j].ss = iNf;
tmp_get++;
tmp_now++;
}
// STL(i, dp);
// db(tmp_ans);
sort(dp.begin(), dp.end(), cmp_ff);
loop(j,0,n){
if(tmp_get == k){
ans = min(ans, tmp_ans);
break;
}
tmp_ans += (long double)dp[j].ff / tmp_now;
tmp_get++;
}
if(tmp_get == k)
ans = min(ans, tmp_ans);
}
sort(org.begin(), org.end(), cmp_ss);
// STL(i, org);
loop(i,0,k+1){
dp = org;
tmp_ans = 0;
tmp_get = 0;
tmp_now = 1;
loop(j,0,i){
if(dp[j].ss == iNf) break;
tmp_ans += (long double)dp[j].ss / tmp_now;
dp[j].ff = iNf;
dp[j].ss = iNf;
tmp_get++;
tmp_now++;
}
sort(dp.begin(), dp.end(), cmp_ff);
loop(j,0,n){
if(tmp_get == k){
ans = min(ans, tmp_ans);
break;
}
tmp_ans += (long double)dp[j].ff / tmp_now;
tmp_get++;
}
if(tmp_get == k)
ans = min(ans, tmp_ans);
}
cout << fixed << setprecision(10) << ans << "\n";
return 0;
}
/*
3
3
1 5
2 3
4 5
*/
/*
2 2
9 10
5 9
*/
Compilation message
Main.cpp: In function 'std::ostream& operator<<(std::ostream&, std::pair<int, int>)':
Main.cpp:14:1: warning: no return statement in function returning non-void [-Wreturn-type]
14 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
3 ms |
212 KB |
Output is correct |
6 |
Correct |
5 ms |
212 KB |
Output is correct |
7 |
Correct |
8 ms |
308 KB |
Output is correct |
8 |
Correct |
13 ms |
304 KB |
Output is correct |
9 |
Correct |
18 ms |
212 KB |
Output is correct |
10 |
Correct |
8 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
3 ms |
212 KB |
Output is correct |
6 |
Correct |
5 ms |
212 KB |
Output is correct |
7 |
Correct |
8 ms |
308 KB |
Output is correct |
8 |
Correct |
13 ms |
304 KB |
Output is correct |
9 |
Correct |
18 ms |
212 KB |
Output is correct |
10 |
Correct |
8 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
212 KB |
Output is correct |
13 |
Correct |
6 ms |
300 KB |
Output is correct |
14 |
Correct |
6 ms |
304 KB |
Output is correct |
15 |
Correct |
15 ms |
300 KB |
Output is correct |
16 |
Correct |
25 ms |
212 KB |
Output is correct |
17 |
Correct |
16 ms |
300 KB |
Output is correct |
18 |
Correct |
29 ms |
292 KB |
Output is correct |
19 |
Correct |
23 ms |
300 KB |
Output is correct |
20 |
Correct |
38 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
26 ms |
300 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
3 ms |
212 KB |
Output is correct |
6 |
Correct |
5 ms |
212 KB |
Output is correct |
7 |
Correct |
8 ms |
308 KB |
Output is correct |
8 |
Correct |
13 ms |
304 KB |
Output is correct |
9 |
Correct |
18 ms |
212 KB |
Output is correct |
10 |
Correct |
8 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
212 KB |
Output is correct |
13 |
Correct |
6 ms |
300 KB |
Output is correct |
14 |
Correct |
6 ms |
304 KB |
Output is correct |
15 |
Correct |
15 ms |
300 KB |
Output is correct |
16 |
Correct |
25 ms |
212 KB |
Output is correct |
17 |
Correct |
16 ms |
300 KB |
Output is correct |
18 |
Correct |
29 ms |
292 KB |
Output is correct |
19 |
Correct |
23 ms |
300 KB |
Output is correct |
20 |
Correct |
38 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |