# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
806193 | 2023-08-04T05:10:10 Z | vjudge1 | Let's Win the Election (JOI22_ho_t3) | C++14 | 1 ms | 384 KB |
#include<bits/stdc++.h> #define fi first #define se second #define ll long long #define ld long double using namespace std ; const int N = 500 ; bool flag1, flag2 ; int n, k ; pair<pair<ld, ld>, int> p[N + 1] ; signed main() { ios_base::sync_with_stdio( 0 ) ; cin.tie( 0 ) ; cout.tie( 0 ) ; cin >> n ; cin >> k ; for(int i = 1 ; i <= n ; i++) { cin >> p[i].fi.fi >> p[i].fi.se ; p[i].se = i ; if(p[i].fi.se != -1) flag1 = 1 ; if(p[i].fi.se != -1 && p[i].fi.se != p[i].fi.fi) flag2 = 1 ; } if(!flag1) { sort(p + 1, p + n + 1) ; ld ans = 0 ; for(int i = 1 ; i <= k ; i++) ans += p[i].fi.fi ; cout << fixed << setprecision(9) << ans ; return 0 ; } if(!flag2) { ld ans = 1e9 ; vector<pair<pair<ld, ld>, int>> v_pos, v_neg ; for(int i = 1 ; i <= n ; i++) { if(p[i].fi.se == -1) v_neg.push_back(p[i]) ; else v_pos.push_back({{p[i].fi.se, p[i].fi.fi}, i}) ; } sort(v_pos.begin(), v_pos.end()) ; sort(v_neg.begin(), v_neg.end()) ; for(int i = -1 ; i < min(k, (int)v_pos.size()) ; i++) { int now = i + 1, uk1 = i + 1, uk2 = 0 ; ld sum = 0, cnt = 1 ; for(int j = 0 ; j <= i ; j++) { sum += v_pos[j].fi.fi / cnt ; cnt++ ; } while(now < k) { ld mn = 1e9 ; if(uk1 < v_pos.size()) mn = v_pos[uk1].fi.se ; if(uk2 < v_neg.size()) mn = min(mn, v_neg[uk2].fi.fi) ; sum += mn / cnt ; if(uk1 < v_pos.size() && mn == v_pos[uk1].fi.se) uk1++ ; else uk2++ ; now++ ; } ans = min(ans, sum) ; } cout << fixed << setprecision(9) << ans ; return 0 ; } return 0 ; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 340 KB | Output is correct |
8 | Correct | 1 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 340 KB | Output is correct |
8 | Correct | 1 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 340 KB | Output is correct |
13 | Correct | 1 ms | 340 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 340 KB | Output is correct |
16 | Correct | 1 ms | 384 KB | Output is correct |
17 | Correct | 1 ms | 340 KB | Output is correct |
18 | Correct | 1 ms | 340 KB | Output is correct |
19 | Correct | 1 ms | 340 KB | Output is correct |
20 | Correct | 1 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 340 KB | Output is correct |
8 | Correct | 1 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 340 KB | Output is correct |
13 | Correct | 1 ms | 340 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 340 KB | Output is correct |
16 | Correct | 1 ms | 384 KB | Output is correct |
17 | Correct | 1 ms | 340 KB | Output is correct |
18 | Correct | 1 ms | 340 KB | Output is correct |
19 | Correct | 1 ms | 340 KB | Output is correct |
20 | Correct | 1 ms | 340 KB | Output is correct |
21 | Incorrect | 1 ms | 212 KB | Output isn't correct |
22 | Halted | 0 ms | 0 KB | - |