#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pii pair<double,double>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf push_front
#define all(x) x.begin(),x.end()
#define de(x) cout << #x << ' ' << x << '\n';
template<class T> void prt(T l,T r){
while(l!=r) cout << *l << ' ',l++;
cout << '\n';
}
const int N=1e6+5,M=1e9+7,INF=1e18;
signed main(){
IO
int n,k;cin >> n >> k;
vector<double> a(n),b(n);
for(int i=0;i<n;i++) cin >> a[i] >> b[i];
int cnt=n;
for(int i=0;i<n;i++) if(b[i]==-1) b[i]=INF,cnt--;
double ans=0;
set<int> A,B;
vector<pii> v(n);
for(int i=0;i<n;i++){
v[i]=mp(a[i],i);
}
sort(all(v));
for(int i=0;i<k;i++){
A.insert(v[i].ss);
ans+=v[i].ff;
}
for(double c=1;c<=min(cnt,k);c++){
int mna=INF,mnai=-1;
for(auto x:A){
if(a[x]<mna){
mna=a[x];
mnai=x;
}
}
int mn=INF,mni=-1;
for(int i=0;i<n;i++){
if(B.count(i)) continue;
if(A.count(i)){
if(b[i]-a[i]<mn){
mn=b[i]-a[i];
mni=i;
}
}else{
if(b[i]-mna<mn){
mn=b[i]-mna;
mni=i;
}
}
}
if(A.count(mni)){
A.erase(mni);
B.insert(mni);
}else{
A.erase(mnai);
B.insert(mni);
}
double sum=0,cc=1;
vector<double> bb,aa;
for(auto x:B){
bb.pb(b[x]);
}
for(auto x:A){
aa.pb(a[x]);
}
sort(all(bb));
sort(all(aa));
for(int i=0;i<bb.size();i++){
sum+=bb[i]/cc;
cc++;
}
for(int i=0;i<aa.size();i++){
sum+=aa[i]/cc;
}
ans=min(ans,sum);
}
cout << setprecision(15) << fixed;
cout << ans << '\n';
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:83:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long double>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
83 | for(int i=0;i<bb.size();i++){
| ~^~~~~~~~~~
Main.cpp:87:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long double>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
87 | for(int i=0;i<aa.size();i++){
| ~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
4 ms |
376 KB |
Output is correct |
13 |
Incorrect |
5 ms |
340 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
31 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
4 ms |
376 KB |
Output is correct |
13 |
Incorrect |
5 ms |
340 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |