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;
#define int long long
#define db long double
#define MAX 502
int n, k;
pair<db, db> info[MAX];
bool cmp(pair<db, db> a, pair<db, db> b){
if (a.second == -1) a.second = 1000000000;
if (b.second == -1) b.second = 1000000000;
return a.second > b.second;
}
main(){
cin >> n >> k;
for (int x = 0; x < n; x++) cin >> info[x].first >> info[x].second;
db ans = 1000000000000000LL;
for (int x = 0; x <= n; x++){
//make use of x colabs
//initial sort is optimal for 0 colabs
vector<pair<db, db>> colabSect;
vector<pair<db, db>> voteSect;
//wait is dp even needed
for (int y = 0; y < n; y++) voteSect.push_back(info[y]);
sort(voteSect.begin(), voteSect.end(), cmp); //give cheapest
for (int y = 0; y < x; y++){
colabSect.push_back(voteSect.back());
//cout << voteSect.back().first << ' ' << voteSect.back().second << '\n';
voteSect.pop_back();
}
//cout << '\n' << '\n';
if (colabSect.size() != 0 && colabSect.back().second == -1) break;
sort(voteSect.begin(), voteSect.end()); //return to cheapest votes
int votesNeeded = k - (int)colabSect.size();
if (votesNeeded < 0) break;
int colabCount = 1;
db curAns = 0;
for (auto y : colabSect){
curAns += y.second/colabCount; colabCount++;
}
for (int y = 0; y < votesNeeded; y++){
curAns += voteSect[y].first/colabCount;
}
//cout << curAns << "!!!\n\n";
ans = min(curAns, ans);
}
cout << std::setprecision(9) << ans;
}
Compilation message (stderr)
Main.cpp:19:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
19 | main(){
| ^~~~
# | 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... |