-
Notifications
You must be signed in to change notification settings - Fork 0
/
abc176_e.cpp
50 lines (39 loc) · 902 Bytes
/
abc176_e.cpp
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;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int H, W, M;
cin >> H >> W >> M;
map<int,int> atRow, atCol;
map<int, vector<int>> atRowCord;
for (int i = 0; i < M; i++) {
int hi, wi;
cin >> hi >> wi;
atRow[hi]++;
atCol[wi]++;
atRowCord[hi].emplace_back(wi);
}
set<pair<int,int>> colSt;
for (auto& [c, q] : atCol) {
colSt.emplace(q, c);
}
int ans = 0;
for (auto& [hi , ws] : atRowCord) {
int bestInHi = 0;
for (auto wi : ws) {
colSt.erase({atCol[wi], wi});
bestInHi = max(bestInHi, atCol[wi]);
}
int bestCol = 0;
if (!colSt.empty())
bestCol = (*colSt.rbegin()).first;
bestCol = max(bestCol, bestInHi-1);
ans = max(ans, atRow[hi] + bestCol);
for (auto wi : ws) {
colSt.emplace(pair<int,int>{atCol[wi], wi});
}
}
cout << ans << '\n';
}
// AC, greddy, brute force, data structures