Submission #1092655

#TimeUsernameProblemLanguageResultExecution timeMemory
1092655ortsacLet's Win the Election (JOI22_ho_t3)C++17
10 / 100
9 ms600 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define db long double int INF = 0x3f3f3f3f; struct Val { int a, b, idx; Val(int x = 0, int y = 0, int z = 0) : a(x), b(y), idx(z) {} }; bool comp1(const Val& a, const Val& b) { return (make_pair(a.b, a.idx) < make_pair(b.b, b.idx)); } bool comp2(const Val& a, const Val& b) { return (make_pair(a.a, a.idx) < make_pair(b.a, b.idx)); } int32_t main() { int n, k; cin >> n >> k; vector<Val> v(n); for (int i = 0; i < n; i++) { cin >> v[i].a >> v[i].b; if (v[i].b == -1) v[i].b = INF; v[i].idx = (i + 1); } sort(v.begin(), v.end(), comp1); cout << fixed << setprecision(7); db ans = INF; for (int i = 0; i <= n; i++) { //cout << i << "\n"; db mC = 0; for (int j = 0; j < i; j++) { mC += (((db)v[j].b)/((db)(j + 1))); //cout << v[i].idx << " " << mC << " " << v[i].b << "\n"; } //cout << "getting rest\n"; vector<Val> others; for (int j = i; j < n; j++) { others.push_back(v[j]); } sort(others.begin(), others.end(), comp2); int rem = (k - i); for (int j = 0; j < rem; j++) { mC += (((db)others[j].a)/((db)(i + 1))); //cout << others[j].idx << " " << mC << "\n"; } ans = min(ans, mC); } cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...