Submission #1092656

#TimeUsernameProblemLanguageResultExecution timeMemory
1092656ortsacLet's Win the Election (JOI22_ho_t3)C++17
10 / 100
9 ms472 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define db long double int INF = 0x3f3f3f3f3f3f3f3f; 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(14); db ans = INF; for (int i = 0; i <= k; 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...