結果

問題 No.2488 Mod Sum Maximization
ユーザー hiromi_ayasehiromi_ayase
提出日時 2023-09-29 22:48:51
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,087 bytes
コンパイル時間 5,188 ms
コンパイル使用メモリ 306,868 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-29 22:49:04
合計ジャッジ時間 10,545 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/all>
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define FAST_IO                \
  ios::sync_with_stdio(false); \
  cin.tie(0);
const i64 INF = 1001001001001001001;
using Modint = atcoder::static_modint<998244353>;

int main() {
  FAST_IO

  int n;
  cin >> n;
  vector a(n, 0LL);
  for (auto i : views::iota(0, n)) {
    cin >> a[i];
  }
  auto sum = accumulate(a.begin(), a.end(), 0);
  auto maxVal = accumulate(a.begin(), a.end(), -1, [](i64 a, i64 b) { return max(a, b); });
  auto minVal = accumulate(a.begin(), a.end(), INF, [](i64 a, i64 b) { return min(a, b); });

  // min1 min2 max2 max1
  // min1 ... max1 min2 ... max2

  auto ans = sum - maxVal + maxVal % minVal;
  for (auto i : views::iota(1, n)) {
    for (auto j : views::iota(i, n - 1)) {

      auto minVal2 = a[i];
      auto maxVal2 = a[j];
      auto cur = sum - maxVal - maxVal2;
      cur += maxVal % minVal2 + maxVal2 % minVal;

      ans = max(ans, cur);
    }
  }

  cout << ans << endl;
}
0