Advertisement
ivnikkk

Untitled

May 26th, 2022
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #define debug(l) cerr<<#l<<' '<<l<<'\n';
  3. #include "bits/stdc++.h"
  4. using namespace std;
  5. #define all(a) a.begin(), a.end()
  6. typedef long long ll;
  7. typedef pair<ll, ll> pll;
  8. typedef long double ld;
  9. const int N = 4e5 + 1;
  10. ll cnt[N] = {}, pref[N], n;
  11. signed main() {
  12. #ifdef _DEBUG
  13.     freopen("input.txt", "r", stdin);
  14.     freopen("output.txt", "w", stdout);
  15. #endif
  16.     ios_base::sync_with_stdio(false);
  17.     cin.tie(nullptr);
  18.     cout.tie(nullptr);
  19.     cin >> n;
  20.     for (int i = 0; i < n; i++) {
  21.         ll x;
  22.         cin >> x;
  23.         cnt[x]++;
  24.     }
  25.     pref[0] = 0;
  26.     for (int i = 1; i < N; i++) {
  27.         pref[i] = pref[i - 1] + cnt[i];
  28.     }
  29.     ll ans = 0;
  30.     for (int i = 1; i < N; i++) {
  31.         ll pre_ans = 0;
  32.         if (cnt[i]) {
  33.             for (int j = i; j + i <= N; j += i) {
  34.                 pre_ans += 1LL * (pref[j + i - 1] - pref[j - 1]) * j;
  35.             }
  36.         }
  37.         ans = max(ans, pre_ans);
  38.     }
  39.     cout << ans << '\n';
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement