結果
問題 |
No.2390 Udon Coupon (Hard)
|
ユーザー |
|
提出日時 | 2023-07-21 23:01:04 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 865 bytes |
コンパイル時間 | 1,598 ms |
コンパイル使用メモリ | 175,444 KB |
実行使用メモリ | 32,772 KB |
最終ジャッジ日時 | 2024-09-22 00:32:36 |
合計ジャッジ時間 | 3,387 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 44 WA * 3 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); ll n; cin >> n; vector<pair<ll, ll>> a(3); for(int i = 0; i < 3; i++){ cin >> a[i].first >> a[i].second; } sort(a.begin(), a.end(), [&](pair<ll, ll> lhs, pair<ll, ll> rhs){ return lhs.second * rhs.first < lhs.first * rhs.second; }); ll lcmv = a[0].first * a[1].first / __gcd(a[0].first, a[1].first); vector<ll> dp(lcmv + 1); for(int i = 0; i < 3; i++){ ll v1, v2; tie(v1, v2) = a[i]; for(int j = 0; j + v1 <= lcmv; j++){ dp[j + v1] = max(dp[j + v1], dp[j] + v2); } } ll ans = 0; for(int j = 0; j <= lcmv && j <= n; j++){ ans = max(ans, dp[j] + ((n - j) / a[2].first) * a[2].second); } cout << ans << '\n'; }