結果
問題 | No.2495 Three Sets |
ユーザー |
👑 ![]() |
提出日時 | 2023-10-06 22:36:06 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 671 ms / 3,000 ms |
コード長 | 2,147 bytes |
コンパイル時間 | 3,254 ms |
コンパイル使用メモリ | 260,432 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-26 16:41:01 |
合計ジャッジ時間 | 7,162 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define FOR(i,m,n) for(int i=(m);i<(n);++i)#define REP(i,n) FOR(i,0,n)using ll = long long;constexpr int INF = 0x3f3f3f3f;constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;constexpr double EPS = 1e-8;constexpr int MOD = 998244353;// constexpr int MOD = 1000000007;constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1};constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1};constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1};template <typename T, typename U>inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; }template <typename T, typename U>inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; }struct IOSetup {IOSetup() {std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);std::cout << fixed << setprecision(20);}} iosetup;int main() {array<vector<int>, 3> a{};for (vector<int>& a_i : a) {int n; cin >> n;a_i.resize(n);}for (vector<int>& a_i : a) {for (int& a_ij : a_i) cin >> a_ij;ranges::sort(a_i, greater<int>());a_i.emplace(a_i.begin(), 0);partial_sum(a_i.begin(), a_i.end(), a_i.begin());}const auto score = [&](const int i, const int j, const int k) -> ll {return ll{a[0][i]} * j + ll{a[1][j]} * k + ll{a[2][k]} * i;};const auto bin_search = [&](const int i, const int j) -> ll {int lb_k = 0, ub_k = a[2].size() - 1;while (lb_k + 3 <= ub_k) {const int m1 = (lb_k + lb_k + ub_k) / 3, m2 = (lb_k + ub_k + ub_k) / 3;if (score(i, j, m1) < score(i, j, m2)) {lb_k = m1;} else {ub_k = m2;}}ll max_score = -LINF;FOR(k, lb_k, ub_k + 1) chmax(max_score, score(i, j, k));return max_score;};ll ans = -LINF;REP(i, a[0].size()) {int lb_j = 0, ub_j = a[1].size() - 1;while (lb_j + 3 <= ub_j) {const int m1 = (lb_j + lb_j + ub_j) / 3, m2 = (lb_j + ub_j + ub_j) / 3;if (bin_search(i, m1) < bin_search(i, m2)) {lb_j = m1;} else {ub_j = m2;}}FOR(j, lb_j, ub_j + 1) chmax(ans, bin_search(i, j));}cout << ans << '\n';return 0;}