Language: C++

#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

const ll INF = (ll)1e18 + 10;

class FordFulkerson {
public:
    FordFulkerson(ll n) : n_(n), graph_(n) {}

    // fromからtoへ向かう容量capの辺をグラフに追加する
    void addEdge(ll from, ll to, ll cap) {
        graph_[from].push_back({ to, cap, (ll)graph_[to].size() });
        graph_[to].push_back({ from, 0, (ll)graph_[from].size() - 1 });
    }
    
    // sからtへの最大流を求める
    ll getflow(ll s, ll t) {
        ll flow = 0;
        while (true) {
            used_.assign(n_, false);
            ll f = dfs(s, t, INF);
            if (f == 0) return flow;
            flow += f;
        }
    }

private:
    struct Edge { ll to, cap, rev; };
    ll n_;
    vector<vector<Edge>> graph_;
    vector<bool> used_;
    
    // 増加パスをdfsで探す
    ll dfs(ll v, ll t, ll f) {
        if (v == t) return f;
        used_[v] = true;
        for (auto &e : graph_[v]) {
            if (!used_[e.to] && e.cap > 0) {
                ll d = dfs(e.to, t, min(f, e.cap));
                if (d > 0) {
                    e.cap -= d;
                    graph_[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
};

int main() {
    ll N;
    cin >> N;
    FordFulkerson ff(N + 2);
    ll s = 0;
    for (ll i = 1; i <= N; i++) {
        ll a;
        cin >> a;
        s += max(0ll, a);
        if (a <= 0) {
            ff.addEdge(0, i, -a);
        } else {
            ff.addEdge(i, N + 1, a);
        }

        for (ll j = i * 2; j <= N; j += i) {
            ff.addEdge(i, j, INF);
        }
    }
    cout << s - ff.getflow(0, N + 1) << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:60:17: error: no matching function for call to 'max(long long int, ll&)'
   60 |         s += max(0ll, a);
      |              ~~~^~~~~~~~
In file included 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_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:60:17: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'll' {aka 'long int'})
   60 |         s += max(0ll, a);
      |              ~~~^~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:60:17: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   60 |         s += max(0ll, a);
      |              ~~~^~~~~~~~