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;
#define int ll
#define starburst ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pii pair<int,int>
#define pb push_back
#define ff first
#define ss second
#define N 100005
struct city{
int i, a, b;
};
void solve(){
int n, k, cnt = 0, j = 0; cin >> n >> k;
double ans = 1000000;
vector<int> used(n, 0);
vector<city> v(n);
for(auto &[i, a, b]:v){
cin >> a >> b;
if(b != -1) ++cnt;
b = (b == -1 ? 1000000 : b);
i = j++;
}
for(j = 0; j <= min(k, cnt); ++j){
int c = 1;
double t = 0;
used.assign(n, 0);
sort(v.begin(), v.end(), [](city a, city b){return a.b < b.b;});
for(int i = 0; i < j; ++i){
t += (double)v[i].b / (double) c;
c++;
used[v[i].i] = 1;
}
sort(v.begin(), v.end(), [](city a, city b){return a.a < b.a;});
for(int i = 0, cc = 0; cc < (k - j) && i < n; ++i){
if(used[v[i].i]) continue;
t += (double)v[i].a / (double) c;
++cc;
}
ans = min(ans, t);
}
cout << fixed << setprecision(9) << ans << '\n';
}
signed main(){
starburst
int t = 1; //cin >> t;
while(t--) solve();
}
# | 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... |