Language: C++

#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
#define rep(i,n) for (ll i=0; i < (ll)(n); i++)

int main(void){
    int H,W,M;
    cin>>H>>W>>M;
    vector<int> h(M);
    vector<int> w(M);
    rep(i,M)cin>>h[i]>>w[i];
    vector<int> bomb(M,0);
    // 各行・列の爆弾個数を取得
    vector<int> a(H,0);
    vector<int> b(W,0);
    vector<vector<int>> c(H,vector<int>(W,0));
    rep(i,M){
        a[h[i]-1]++;
        b[w[i]-1]++;
        c[h[i]-1][w[i]-1]++;
    }
    // 全探索
    iterator am=max_element(a.begin(),a.end());
    iterator bm=max_element(b.begin(),b.end());
    vector<int> A;
    vector<int> B;
    int j=0;
    rep(i,H){
        if(a[i]==am){
            A[j]=i;
            j++;
        }
    }
    int k=0;
    rep(i,W){
        if(b[i]==bm){
            B[k]=i;
            k++;
        }
    }
    int ans=0;
    rep(i,j)rep(l,k){
        int bomb=am+bm-c[A[i]][B[l]];
        ans=max(ans,bomb);
        if (ans==am+bm)break;
    }
    cout<<ans<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:25:46: error: class template argument deduction failed:
   25 |     iterator am=max_element(a.begin(),a.end());
      |                                              ^
a.cc:25:46: error: no matching function for call to 'iterator(__gnu_cxx::__normal_iterator<int*, std::vector<int> >)'
In file included from /usr/include/c++/14/bits/stl_algobase.h:65,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator_base_types.h:127:34: note: candidate: 'template<class _Category, class _Tp, class _Distance, class _Pointer, class _Reference> iterator()-> std::iterator<_Category, _Tp, _Distance, _Pointer, _Reference>'
  127 |     struct _GLIBCXX17_DEPRECATED iterator
      |                                  ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_types.h:127:34: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/14/bits/stl_iterator_base_types.h:127:34: note: candidate: 'template<class _Category, class _Tp, class _Distance, class _Pointer, class _Reference> iterator(std::iterator<_Category, _Tp, _Distance, _Pointer, _Reference>)-> std::iterator<_Category, _Tp, _Distance, _Pointer, _Reference>'
/usr/include/c++/14/bits/stl_iterator_base_types.h:127:34: note:   template argument deduction/substitution failed:
a.cc:25:46: note:   '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' is not derived from 'std::iterator<_Category, _Tp, _Distance, _Pointer, _Reference>'
   25 |     iterator am=max_element(a.begin(),a.end());
      |                                              ^
a.cc:26:46: error: class template argument deduction failed:
   26 |     iterator bm=max_element(b.begin(),b.end());
      |                                              ^
a.cc:26:46: error: no matching function for call to 'iterator(__gnu_cxx::__normal_iterator<int*, std::vector<int> >)'
/usr/include/c++/14/bits/stl_iterator_base_types.h:127:34: note: candidate: 'template<class _Category, class _Tp, class _Distance, class _Pointer, class _Reference> iterator()-> std::iterator<_Category, _Tp, _Distance, _Pointer, _Reference>'
  127 |     struct _GLIBCXX17_DEPRECATED iterator
      |                                  ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_types.h:127:34: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/14/bits/stl_iterator_base_types.h:127:34: note: candidate: 'template<class _Category, class _Tp, class _Distance, class _Pointer, class _Reference> iterator(std::iterator<_Category, _Tp, _Distance, _Pointer, _Reference>)-> std::iterator<_Category, _Tp, _Distance, _Pointer, _Reference>'
/usr/include/c++/14/bits/stl_iterator_base_types.h:127:34: note:   template argument deduction/substitution failed:
a.cc:26:46: note:   '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' is not derived from 'std::iterator<_Category, _Tp, _Distance, _Pointer, _Reference>'
   26 |     iterator bm=max_element(b.begin(),b.end());
      |                                              ^