結果
| 問題 | No.37 遊園地のアトラクション |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-07-30 05:25:25 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| + 589µs | |
| コード長 | 718 bytes |
| 記録 | |
| コンパイル時間 | 1,893 ms |
| コンパイル使用メモリ | 178,752 KB |
| 実行使用メモリ | 5,888 KB |
| 最終ジャッジ日時 | 2026-07-30 05:25:29 |
| 合計ジャッジ時間 | 2,781 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 27 |
ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
int main(void){
int t, n; cin >> t >> n;
vector<int> c(n), v(n);
for(auto&x:c) cin >> x;
for(auto&x:v) cin >> x;
for(int i=0; i<n; i++){
int nv=v[i]; nv/=2;
while(nv){
c.push_back(c[i]);
v.push_back(nv);
nv/=2;
}
}
int m=c.size();
vector<int> dp(t+1, -1e9);
dp[0]=0;
for(int i=0; i<m; i++){
vector<int> old(t+1, -1e9);
swap(old, dp);
for(int j=0; j<=t; j++){
dp[j]=max(dp[j], old[j]);
if(old[j]>=0&&j+c[i]<=t){
dp[j+c[i]]=max(dp[j+c[i]], old[j]+v[i]);
}
}
}
cout << *max_element(begin(dp), end(dp)) << endl;
return 0;
}