結果
| 問題 |
No.54 Happy Hallowe'en
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-04-09 12:08:42 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 27 ms / 5,000 ms |
| コード長 | 628 bytes |
| コンパイル時間 | 430 ms |
| コンパイル使用メモリ | 46,464 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-15 17:11:44 |
| 合計ジャッジ時間 | 1,500 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:6:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
6 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
main.cpp:9:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
9 | scanf("%d%d",&v[i].first,&v[i].second);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <vector>
#include <algorithm>
#include <cstdio>
int main(){
int n,vmax=0,tmax=0;
scanf("%d",&n);
std::vector<std::pair<int,int> >v(n);
for(int i=0;i<n;i++){
scanf("%d%d",&v[i].first,&v[i].second);
if(vmax<v[i].first)vmax=v[i].first;
if(tmax<v[i].second)tmax=v[i].second;
}
std::sort(v.begin(),v.end(),[](std::pair<int,int> a,std::pair<int,int> b)->bool{return a.first+a.second<b.first+b.second;});
std::vector<int>bag(tmax+vmax+1);
bag[0]=1;
for(int i=0;i<n;i++){
for(int j=v[i].second-1;j>=0;j--)bag[j+v[i].first]|=bag[j];
}
for(int i=tmax+vmax;i>=0;i--)if(bag[i]){
printf("%d\n",i);
break;
}
}