結果
問題 | No.2495 Three Sets |
ユーザー |
![]() |
提出日時 | 2023-10-07 00:08:36 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 553 ms / 3,000 ms |
コード長 | 1,639 bytes |
コンパイル時間 | 2,047 ms |
コンパイル使用メモリ | 165,452 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-26 17:30:14 |
合計ジャッジ時間 | 10,614 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 |
ソースコード
#include <bits/stdc++.h>using namespace std;typedef long long int ll;typedef unsigned long long ull;typedef long double ld;int dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }, dy[8] = { 0, 1, 0, -1, 1, -1, 1, -1 };const long long mod = 998244353;const ll inf = 1LL << 60;const int INF = 5e8;const int M = 3000;int main(){int na, nb, nc;cin >> na >> nb >> nc;vector<int> a(na), b(nb), c(nc);for (int i = 0; i < na; i++)cin >> a[i];for (int i = 0; i < nb; i++)cin >> b[i];for (int i = 0; i < nc; i++)cin >> c[i];auto conv = [&](vector<int>& v) {vector<int> cnt(2 * M + 1);for (int i = 0; i < (int)v.size(); i++) {cnt[v[i] + M]++;}vector<pair<ll, ll>> res(2 * M + 1);ll sum = 0, cntsum = 0;for (int i = M; i >= -M; i--) {cntsum += cnt[i + M];sum += cnt[i + M] * i;res[i + M] = { sum, cntsum };}return res;};auto va = conv(a);auto vb = conv(b);auto vc = conv(c);auto ceil = [&](ll a, ll b) {if (a > 0)return (a + b - 1) / b;elsereturn a / b;};ll ans = -inf;for (auto [sb, cb] : vb) {for (auto [sc, cc] : vc) {if (cb == 0) {ans = max(ans, na * sc + sb * cc);} else {ll lim = ceil(-sc, cb);auto [sa, ca] = lim > M ? pair<ll, ll> { 0, 0 } : va[max(0LL, lim + M)];ans = max(ans, sa * cb + sb * cc + sc * ca);}}}cout << ans << endl;}