結果
| 問題 |
No.2390 Udon Coupon (Hard)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-07-21 23:02:21 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 82 ms / 2,000 ms |
| コード長 | 868 bytes |
| コンパイル時間 | 1,708 ms |
| コンパイル使用メモリ | 177,120 KB |
| 実行使用メモリ | 18,944 KB |
| 最終ジャッジ日時 | 2024-10-06 01:56:29 |
| 合計ジャッジ時間 | 5,652 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 47 |
ソースコード
#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;
});
int lcmv = 2000000;
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++){
for(int k = 0; k < 3; k++){
ans = max(ans, dp[j] + ((n - j) / a[k].first) * a[k].second);
}
}
cout << ans << '\n';
}