cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) { for (int k = 1; k <= n; k++) { unq.push_back(a[i] * k); // 处理倍数,预备去重 } } sort(unq.begin(), unq.end()); int cnt = unique(unq.begin(), unq.end()) - unq.begin(); // 去重,顺带升序排序 int disc = 0; for (int i = 0; i < cnt; i++) { // 离散化 discrete[unq[i]] = ++disc; b[disc] = unq[i]; // 去重前就已完成排序,直接赋值 } for (int i = 1; i <= n; i++) { for (int k = 1; k <= n; k++) { add(discrete[a[i] * k] + n, i); } } ll ans = 0; int res = 0; for (int i = 1; i <= cnt; i++) { if (hungary(i + n)) { // 优化 memset(st, false, sizeof st); res++; ans += b[i]; } if (res == n) break; // 总共匹配n个a } cout << ans << endl; return0; }