-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsol.cpp
More file actions
executable file
·50 lines (40 loc) · 1.19 KB
/
Copy pathsol.cpp
File metadata and controls
executable file
·50 lines (40 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <bits/stdc++.h>
using namespace std;
int main()
{
fixed(cout);
cout.precision(10);
int precincts, districts;
cin >> precincts >> districts;
vector<pair<int, int>> D(districts + 1, {0, 0});
while (precincts--)
{
int district, A, B;
cin >> district >> A >> B;
D[district].first += A;
D[district].second += B;
}
double total_votes = 0;
double total_wasted_A = 0;
double total_wasted_B = 0;
for (int i = 1; i < districts + 1; ++i)
{
total_votes += D[i].first;
total_votes += D[i].second;
int needed = (int)(floor((double)(D[i].first + D[i].second) / 2.0) + 1.0);
if (D[i].first > D[i].second)
{
total_wasted_A += D[i].first - needed;
total_wasted_B += D[i].second;
cout << "A " << D[i].first - needed << " " << D[i].second << endl;
}
else
{
total_wasted_A += D[i].first;
total_wasted_B += D[i].second - needed;
cout << "B " << D[i].first << " " << D[i].second - needed << endl;
}
}
cout << abs(total_wasted_A - total_wasted_B) / total_votes << endl;
return 0;
}