Submission #702745

#TimeUsernameProblemLanguageResultExecution timeMemory
702745Chal1shkanLet's Win the Election (JOI22_ho_t3)C++14
5 / 100
1 ms340 KiB
# include <bits/stdc++.h> # define pb push_back # define ff first # define ss second # define nl "\n" # define sz(x) ((int)(x).size()) # define deb(x) cerr << #x << " = " << x << endl; typedef long long ll; typedef unsigned long long ull; typedef long double ld; const ll maxn = 5e2 + 25; const ll inf = 2e9 + 0; const ll mod = 998244353; const ll dx[] = {-1, 1, 0, 0}; const ll dy[] = {0, 0, -1, 1}; using namespace std; ll n, k, pref[maxn]; pair <ll, ll> p[maxn]; bool used[maxn]; bool cmp (pair <pair <ll, ll>, ll> x, pair <pair <ll, ll>, ll> y) { if (x.ff.ss != y.ff.ss) { return x.ff.ss < y.ff.ss; } else { return x.ff.ff < y.ff.ff; } } void ma1n (/* SABR */) { cin >> n >> k; for (ll i = 1; i <= n; ++i) { cin >> p[i].ff >> p[i].ss; } sort(p + 1, p + 1 + n); vector < pair <pair <ll, ll>, ll> > v; for (ll i = 1; i <= n; ++i) { if (p[i].ss != -1) { v.pb({p[i], i}); } } sort(v.begin(), v.end(), cmp); for (ll i = 1; i <= sz(v); ++i) { pref[i] = pref[i - 1] + v[i - 1].ff.ss; // cout << v[i - 1].ff.ff << ' ' << v[i - 1].ff.ss << nl; } //dp[i][j][0, 1] //1...i //0...j //0, 1 // ld ans = inf; for (ll i = 0; i <= sz(v); ++i) { ld cur = pref[i]; ll cnt = i; if (i) { used[v[i - 1].ss] = 1; } for (ll j = 1; j <= n && cnt < k; ++j) { if (used[j]) continue; cur += (ld)(p[j].ff) / (ld)(i + 1); cnt++; } ans = min(ans, cur); } cout << fixed << setprecision(9) << ans; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); // freopen("angry.in", "r", stdin); // freopen("angry.out", "w", stdout); int ttt = 1; // cin >> ttt; for (int test = 1; test <= ttt; ++test) { // cout << "Case " << test << ":" << ' '; ma1n(); } 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...