結果
問題 | No.37 遊園地のアトラクション |
ユーザー |
|
提出日時 | 2015-10-29 16:40:42 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 544 bytes |
コンパイル時間 | 453 ms |
コンパイル使用メモリ | 45,056 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-10 13:08:04 |
合計ジャッジ時間 | 1,609 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 27 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:7:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 7 | scanf("%d%d",&T,&N); | ~~~~~^~~~~~~~~~~~~~ main.cpp:9:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 9 | for(int i=0;i<N;i++)scanf("%d",&v[i].first); | ~~~~~^~~~~~~~~~~~~~~~~~ main.cpp:10:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 10 | for(int i=0;i<N;i++)scanf("%d",&v[i].second); | ~~~~~^~~~~~~~~~~~~~~~~~~
ソースコード
#include <vector> #include <algorithm> #include <cstdio> using namespace std; int main(){ int T,N,S=0; scanf("%d%d",&T,&N); vector<pair<int,int> >v(N); for(int i=0;i<N;i++)scanf("%d",&v[i].first); for(int i=0;i<N;i++)scanf("%d",&v[i].second); for(;N--;){ int x=v[N].first,y=v[N].second; for(y/=2;y;y/=2)v.push_back(make_pair(x,y)); } vector<int>bag(T+1); for(int i=0;i<v.size();i++)for(int j=T;j>=v[i].first;j--)bag[j]=max(bag[j],bag[j-v[i].first]+v[i].second); int r=0; for(int i=0;i<=T;i++)r=max(r,bag[i]); printf("%d\n",r); }