Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #define debug(l) cerr<<#l<<' '<<l<<'\n';
- #include "bits/stdc++.h"
- using namespace std;
- #define all(a) a.begin(), a.end()
- typedef long long ll;
- typedef pair<ll, ll> pll;
- typedef long double ld;
- const int N = 4e5 + 1;
- ll cnt[N] = {}, pref[N], n;
- signed main() {
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- cin >> n;
- for (int i = 0; i < n; i++) {
- ll x;
- cin >> x;
- cnt[x]++;
- }
- pref[0] = 0;
- for (int i = 1; i < N; i++) {
- pref[i] = pref[i - 1] + cnt[i];
- }
- ll ans = 0;
- for (int i = 1; i < N; i++) {
- ll pre_ans = 0;
- if (cnt[i]) {
- for (int j = i; j + i <= N; j += i) {
- pre_ans += 1LL * (pref[j + i - 1] - pref[j - 1]) * j;
- }
- }
- ans = max(ans, pre_ans);
- }
- cout << ans << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement