fork download
  1. //BRUTE FORCE
  2. #include<bits/stdc++.h>
  3. #define ull unsigned long long
  4. #define ll long long
  5. #define all(x) x.begin(), x.end()
  6. using namespace std;
  7. const int maxn = 1e5 + 1;
  8. ll A[maxn];
  9. vector<ll> D[46];
  10. pair<ll, ll> scs[maxn];
  11. int sumDigit(int n) {
  12. int s = 0;
  13. while (n != 0) {
  14. s += n % 10;
  15. n /= 10;
  16. }
  17. return s;
  18. }
  19. int cntDigit(int n) {
  20. int cnt = 0;
  21. while (n != 0) {
  22. cnt++;
  23. n /= 10;
  24. }
  25. return cnt;
  26. }
  27. ll lt[12];
  28. void tenEn() {
  29. lt[0] = 1;
  30. for (int i = 1; i <= 10; ++i) {
  31. lt[i] = lt[i - 1] * 10;
  32. }
  33. }
  34. int main() {
  35. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  36. // freopen("file.inp","r",stdin);
  37. // freopen("file.out","w",stdout);
  38. tenEn();
  39. int n;
  40. ll res = 0;
  41. cin >> n;
  42. for (int i = 1; i <= n; ++i) {
  43. cin >> A[i];
  44. D[sumDigit(A[i])].push_back(A[i]);
  45. }
  46. for (int i = 0; i <= 45; ++i) {
  47. if (D[i].size() < 2) continue;
  48. for (int j = 0; j < D[i].size(); ++j) {
  49. scs[j].first = cntDigit(D[i][j]); scs[j].second = D[i][j];
  50. }
  51. for (int j = 0; j < D[i].size(); ++j) {
  52. for (int k = j + 1; k < D[i].size(); ++k) {
  53. ll a = (scs[j].second * lt[cntDigit(scs[k].second)] + scs[k].second);
  54. ll b = (scs[k].second * lt[cntDigit(scs[j].second)] + scs[j].second);
  55. res = max(res, max(a, b));
  56. }
  57. }
  58. }
  59. cout << res;
  60. }
Success #stdin #stdout 0.01s 5280KB
stdin
6
47 77 95 12 3 3000
stdout
300012