Submission #800431

#TimeUsernameProblemLanguageResultExecution timeMemory
800431caganyanmazLet's Win the Election (JOI22_ho_t3)C++17
10 / 100
2 ms308 KiB
#include <bits/stdc++.h> //#define double long double #define mp(x...) array<int, 2>({x}) using namespace std; constexpr static int INF = 1e8; constexpr static int MXSIZE = 1000; bitset<MXSIZE> added; array<int, 2> a[MXSIZE], b[MXSIZE]; int n, k; double calculate(int cc) { int count = 0; double cost = 0; for (int i = 0; i < cc; i++) { cost += static_cast<double>(b[i][0]) / (i+1); count++; } for (int i = 0; i < n && count < k; i++) { if (added[a[i][1]]) continue; cost += static_cast<double>(a[i][0]) / (cc+1); count++; } assert(count == k); return cost; } int main() { cin >> n; cin >> k; for (int i = 0; i < n; i++) { int aa, bb; cin >> aa >> bb; a[i] = mp(aa, i); bb = bb == -1 ? INF : bb; b[i] = mp(bb, i); } sort(a, a + n); sort(b, b + n); double best = INF; for (int i = 0; i <= k && (i == 0 || b[i-1][0] != INF); i++) { if (i > 0) added[b[i-1][1]] = true; best = min(best, calculate(i)); } cout << fixed; cout << setprecision(20); cout << best << "\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...