Submission #871112

#TimeUsernameProblemLanguageResultExecution timeMemory
871112HorizonWestLet's Win the Election (JOI22_ho_t3)C++17
10 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define db double #define ll __int128 #define int long long #define pb push_back #define fs first #define sd second #define Mod long(1e9 + 7) #define all(x) x.begin(), x.end() #define unvisited long(-1) #define Eps double(1e-9) #define _for(i, n) for(int i = 0; i < (n); i++) #define dbg(x) cout << #x ": " << x << endl; const int Max = 1e6 + 7, Inf = 1e9 + 7; void print(bool x) { cout << (x ? "YES" : "NO") << endl; } string tostring (__int128 x) { string ans = ""; while(x > 0) { ans += (x % 10 + '0'); x /= 10; } reverse(all(ans)); return ans; } void printdb(double ans, int k) { cout << setiosflags(ios::fixed) << setiosflags(ios::showpoint) << setprecision(k) << ans << endl; } void solve() { int n, k; cin >> n >> k; vector <pair<db, db>> a(n), b(n); for(int i = 0; i < n; i++) { cin >> a[i].fs >> b[i].fs; a[i].sd = b[i].sd = i; if(b[i].fs == -1) b[i].fs = Inf; } sort(all(a)); sort(all(b)); db ans = Inf, t = 0.0; vector <db> f(n+1, 1); for(db i = 1; i <= k; i++) { db Z = 0.0; db c = 0; for(db j = 0; j < n; j++) { if(c == k - i + 1) break; // cout << a[j].fs << " " << f[a[j].sd] << endl; c += f[a[j].sd]; Z += f[a[j].sd] * a[j].fs; } //cout << Z << " " << t << endl; Z = Z / i + t; t = t + b[i-1].fs / i; ans = min(ans, Z); f[b[i-1].sd] = 0.0; if(b[i-1].fs == Inf) break; } printdb(ans, 5); } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); int Q = 1; //cin >> Q; while (Q--) { solve(); } return 0; }
#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...