結果

問題 No.2495 Three Sets
ユーザー KudeKude
提出日時 2023-10-06 22:38:23
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 555 ms / 3,000 ms
コード長 1,946 bytes
コンパイル時間 3,143 ms
コンパイル使用メモリ 269,224 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-10-06 22:38:36
合計ジャッジ時間 12,627 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 277 ms
4,376 KB
testcase_01 AC 309 ms
4,376 KB
testcase_02 AC 408 ms
4,380 KB
testcase_03 AC 283 ms
4,380 KB
testcase_04 AC 276 ms
4,376 KB
testcase_05 AC 304 ms
4,380 KB
testcase_06 AC 455 ms
4,376 KB
testcase_07 AC 427 ms
4,380 KB
testcase_08 AC 471 ms
4,380 KB
testcase_09 AC 283 ms
4,376 KB
testcase_10 AC 283 ms
4,376 KB
testcase_11 AC 500 ms
4,376 KB
testcase_12 AC 462 ms
4,376 KB
testcase_13 AC 515 ms
4,376 KB
testcase_14 AC 542 ms
4,376 KB
testcase_15 AC 517 ms
4,376 KB
testcase_16 AC 544 ms
4,376 KB
testcase_17 AC 521 ms
4,376 KB
testcase_18 AC 71 ms
4,380 KB
testcase_19 AC 95 ms
4,376 KB
testcase_20 AC 555 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n[3];
  rep(i, 3) cin >> n[i];
  constexpr int B = 3010;
  static int cnt[3][2 * B + 1];
  static int cacc[3][2 * B + 2];
  static ll s[3][2 * B + 2];
  rep(i, 3) {
    rep(j, n[i]) {
      int x;
      cin >> x;
      cnt[i][B + x]++;
    }
    rep(j, 2 * B + 1) {
      cacc[i][j + 1] = cacc[i][j] + cnt[i][j];
      s[i][j + 1] = s[i][j] + cnt[i][j] * (j - B);
    }
  }
  ll ans = 0;
  constexpr int INF = 1001001001;
  for (int v0 = -B; v0 <= B + 1; v0++) for (int v2 = -B; v2 <= B + 1; v2++) {
    ll s0 = s[0][B + B + 1] - s[0][B + v0];
    int c0 = cacc[0][B + B + 1] - cacc[0][B + v0];
    ll s2 = s[2][B + B + 1] - s[2][B + v2];
    int c2 = cacc[2][B + B + 1] - cacc[2][B + v2];
    auto flr = [&](ll x, int y) {
      if (x >= 0) return x / y;
      else return -((-x + y - 1) / y);
    };
    ll v1_ll = [&]() -> ll {
      if (c2 == 0) {
        return s0 > 0 ? -INF : INF;
      }
      return flr(-s0, c2);
    }();
    int v1 = clamp<ll>(v1_ll + 1, -B, B + 1);
    ll s1 = s[1][B + B + 1] - s[1][B + v1];
    int c1 = cacc[1][B + B + 1] - cacc[1][B + v1];
    chmax(ans, s0 * c1 + s1 * c2 + s2 * c0);
  }
  cout << ans << '\n';
}
0