結果
| 問題 |
No.2495 Three Sets
|
| コンテスト | |
| ユーザー |
kwm_t
|
| 提出日時 | 2023-10-07 10:52:04 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 410 ms / 3,000 ms |
| コード長 | 1,845 bytes |
| コンパイル時間 | 1,821 ms |
| コンパイル使用メモリ | 197,188 KB |
| 最終ジャッジ日時 | 2025-02-17 06:04:17 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 |
ソースコード
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
//using mint = modint998244353;
//const int mod = 998244353;
//using mint = modint1000000007;
//const int mod = 1000000007;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define P pair<long long,long long>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
inline long long ceil_div(long long x, long long y) { return (x < 0) ? x / y : (x + (y - 1)) / y; }
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int na, nb, nc; cin >> na >> nb >> nc;
const int MX = 3003;
auto f = [&](const int n) {
vector<long long>c(MX * 2 + 1);
rep(i, n) {
int x; cin >> x;
c[MX + x]++;
}
vector<P>res(MX * 2 + 1);
long long cnt = 0, sum = 0;
rrep2(i, -MX, MX + 1) {
cnt += c[i + MX];
sum += c[i + MX] * i;
res[i + MX] = { cnt,sum };
}
return res;
};
auto a = f(na);
auto b = f(nb);
auto c = f(nc);
long long ans = 0;
// Sb,ScをFix
for (auto q : b)for (auto r : c) {
if (0 == q.first) {
long long val = max(0LL, (long long)na * r.second) + q.second * r.first;
chmax(ans, val);
}
else {
long long x = ceil_div(-r.second, q.first);
P p = x > MX ? P(0, 0) : a[max(0LL, x + MX)];
long long val = p.second * q.first + p.first * r.second + q.second * r.first;
chmax(ans, val);
}
}
cout << ans << endl;
return 0;
}
kwm_t