#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define pii pair<int, int>
#define ff first
#define ss second
#define ld long double
#define pb push_back
pii a[200100];
bool cmp(pii a, pii b){
return a.ss < b.ss;
}
void solve(){
int n, k;
cin>>n>>k;
int dmx = 0;
for(int i=1; i<=n; i++){
cin>>a[i].ff>>a[i].ss;
if(a[i].ss == -1){
a[i].ss = 1e9;
}
}
sort(a + 1, a + 1 + n, cmp);
//for(int i=1; i<=n; i++) cout<<a[i].ff<<' '<<a[i].ss<<'\n';
ld ans = 1e18;
for(ld D=1; D<=k; D++){
vector<int> d;
ld res = 0;
int m = k - D+1;
int ok = 1;
for(int i=1; i<=D-1; i++){
d.pb(i);
res += 1.0 * a[i].ss / i;
}
multiset<pii> dd;
for(int i=D; i<=n; i++){
dd.insert({a[i].ff, i});
if(dd.size() > m){
dd.erase(--(dd.end()));
}
}
for(pii x: dd){
res += x.ff / D;
}
//cout<<"________________\n";
//cout<<D<<'\n';
//cout<<res<<'\n';
//for(auto x: dd) cout<<x.ff<<' '<<x.ss<<'\n';
//for(int x: d) cout<<x<<' ';
//cout<<'\n';
ans = min(ans, res);
for(int i=D; i<=n; i++){
//cout<<i<<'\n';
pair<ld, int> mn = {1e18, -1};
res += a[i].ss * 1.0 / (D);
int mx = (dd.size() ?(*dd.begin()).ss :0);
if(dd.find({a[i].ff, i}) != dd.end()){
mx = 0;
dd.erase({a[i].ff, i});
res -= a[i].ff / D;
}
ld g = 0;
d.pb(i);
for(int i=d.size() - 1; i>=0; i--){
int j = d[i];
mn = min(mn, {-a[j].ss * 1.0 / (i + 1) + g - a[mx].ff/D + a[j].ff/D, j});
if(i > 0)g += -a[j].ss * 1.0 / (i + 1) + a[j].ss * 1.0 / i;
}
res += mn.ff;
dd.insert({a[mn.ss].ff, mn.ss});
if(dd.size() > m) dd.erase(--(dd.end()));
vector<int> dg;
for(int x: d){
if(x != mn.ss) dg.pb(x);
}
d = dg;
ans = min(ans, res);
}
}
cout<<fixed<<setprecision(6)<<ans;
}
signed main(){
solve();
}
Compilation message
Main.cpp: In function 'void solve()':
Main.cpp:45:26: warning: comparison of integer expressions of different signedness: 'std::multiset<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
45 | if(dd.size() > m){
| ~~~~~~~~~~^~~
Main.cpp:80:26: warning: comparison of integer expressions of different signedness: 'std::multiset<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
80 | if(dd.size() > m) dd.erase(--(dd.end()));
| ~~~~~~~~~~^~~
Main.cpp:37:13: warning: unused variable 'ok' [-Wunused-variable]
37 | int ok = 1;
| ^~
Main.cpp:23:9: warning: unused variable 'dmx' [-Wunused-variable]
23 | int dmx = 0;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
13 ms |
452 KB |
Output is correct |
6 |
Correct |
38 ms |
344 KB |
Output is correct |
7 |
Correct |
107 ms |
468 KB |
Output is correct |
8 |
Correct |
176 ms |
452 KB |
Output is correct |
9 |
Correct |
230 ms |
348 KB |
Output is correct |
10 |
Correct |
143 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
13 ms |
452 KB |
Output is correct |
6 |
Correct |
38 ms |
344 KB |
Output is correct |
7 |
Correct |
107 ms |
468 KB |
Output is correct |
8 |
Correct |
176 ms |
452 KB |
Output is correct |
9 |
Correct |
230 ms |
348 KB |
Output is correct |
10 |
Correct |
143 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
47 ms |
348 KB |
Output is correct |
13 |
Correct |
47 ms |
440 KB |
Output is correct |
14 |
Correct |
47 ms |
344 KB |
Output is correct |
15 |
Correct |
149 ms |
348 KB |
Output is correct |
16 |
Correct |
158 ms |
596 KB |
Output is correct |
17 |
Correct |
150 ms |
348 KB |
Output is correct |
18 |
Correct |
185 ms |
348 KB |
Output is correct |
19 |
Correct |
206 ms |
348 KB |
Output is correct |
20 |
Correct |
200 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
444 KB |
Output is correct |
9 |
Incorrect |
0 ms |
440 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
444 KB |
Output is correct |
9 |
Incorrect |
0 ms |
440 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
444 KB |
Output is correct |
9 |
Incorrect |
0 ms |
440 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
220 ms |
348 KB |
Output is correct |
2 |
Correct |
225 ms |
348 KB |
Output is correct |
3 |
Correct |
220 ms |
348 KB |
Output is correct |
4 |
Correct |
206 ms |
348 KB |
Output is correct |
5 |
Correct |
202 ms |
348 KB |
Output is correct |
6 |
Correct |
203 ms |
348 KB |
Output is correct |
7 |
Correct |
207 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
13 ms |
452 KB |
Output is correct |
6 |
Correct |
38 ms |
344 KB |
Output is correct |
7 |
Correct |
107 ms |
468 KB |
Output is correct |
8 |
Correct |
176 ms |
452 KB |
Output is correct |
9 |
Correct |
230 ms |
348 KB |
Output is correct |
10 |
Correct |
143 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
47 ms |
348 KB |
Output is correct |
13 |
Correct |
47 ms |
440 KB |
Output is correct |
14 |
Correct |
47 ms |
344 KB |
Output is correct |
15 |
Correct |
149 ms |
348 KB |
Output is correct |
16 |
Correct |
158 ms |
596 KB |
Output is correct |
17 |
Correct |
150 ms |
348 KB |
Output is correct |
18 |
Correct |
185 ms |
348 KB |
Output is correct |
19 |
Correct |
206 ms |
348 KB |
Output is correct |
20 |
Correct |
200 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
444 KB |
Output is correct |
29 |
Incorrect |
0 ms |
440 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |