Language: C++

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <random>
#include <cstdlib>
using namespace std;
int N;
int a[128];
bool flag[128];

#define MAX_N 128
#define INF INT_MAX 

class dinic {
private:
	struct edge { int to, cap, rev; };
	vector<edge> G[MAX_N];
	//sからの深さを記憶
	vector<int> level;
	int V;

	//深さ優先で経路を検索
	//経路を見つけたら流して更新
	int dfs(int v, int t, int f) {
		if (v == t) return f;
		for (int i = 0; i < G[v].size(); i++) {
			edge &e = G[v][i];
			if (e.cap <= 0) continue;
			if (level[v] >= level[e.to]) continue;
			int d = dfs(e.to, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
		return 0;
	}

	//幅優先
	void bfs(int s) {
		level.assign(V, -1);
		queue<int> q;
		q.push(s);
		level[s] = 0;
		for (; !q.empty();) {
			int v = q.front(); q.pop();
			for (int i = 0; i < G[v].size(); i++) {
				struct edge e = G[v][i];
				if (e.cap <= 0) continue;
				//既に通った辺なら
				if (level[e.to] >= 0) continue;
				level[e.to] = level[v] + 1;
				q.push(e.to);
			}
		}
	}


public:
	dinic(int v) {
		V = v;
	}
	void add_edge(int from, int to, int cap) {
		struct edge tmp;
		tmp = { to, cap, int(G[to].size()) };
		G[from].push_back(tmp);
		tmp = { from, 0, int(G[from].size() - 1) };
		G[to].push_back(tmp);
	}

	long long run(int s, int t) {
		long long f = 0;
		for (;;) {
			bfs(s);
			if (level[t] < 0) break;
			f += dfs(s, t, INF);
		}
		return f;
	}
};

void MUL() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	//後半で負の宝石は問答無用で叩き割る
	for (int i = (N + 1 / 2); i < N; i++) {
		a[i] = a[i] < 0 ? 0 : a[i];
	}

	long long ideal = 0;
	for (int i = 0; i < N; i++) {
		ideal += a[i] > 0 ? a[i] : 0;
	}

	memset(flag, 0, sizeof(flag));

	dinic d(N + 2);
	for (int i = 0; i < N; i++) {
		if (a[i] > 0) {
			d.add_edge(0, i + 1, a[i]);
			d.add_edge(i + 1, N + 1, 0);
		}
		else {
			d.add_edge(i + 1, N + 1, -a[i]);
			d.add_edge(0, i + 1, 0);
		}
		for (int j = (i + 1) * 2; j < N + 1; j += i + 1) {
			d.add_edge(j, (i + 1), INF);
		}
	}
	cout << ideal - d.run(0, N + 1) << endl;
}

int main() {
	MUL();
	return 0;
}


Compiler output:
a.cc: In member function 'long long int dinic::run(int, int)':
a.cc:16:13: error: 'INT_MAX' was not declared in this scope
   16 | #define INF INT_MAX
      |             ^~~~~~~
a.cc:81:40: note: in expansion of macro 'INF'
   81 |                         f += dfs(s, t, INF);
      |                                        ^~~
a.cc:10:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    9 | #include <cstdlib>
  +++ |+#include <climits>
   10 | using namespace std;
a.cc: In function 'void MUL()':
a.cc:16:13: error: 'INT_MAX' was not declared in this scope
   16 | #define INF INT_MAX
      |             ^~~~~~~
a.cc:115:48: note: in expansion of macro 'INF'
  115 |                         d.add_edge(j, (i + 1), INF);
      |                                                ^~~
a.cc:16:13: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
   16 | #define INF INT_MAX
      |             ^~~~~~~
a.cc:115:48: note: in expansion of macro 'INF'
  115 |                         d.add_edge(j, (i + 1), INF);
      |                                                ^~~