結果
問題 | No.1583 Building Blocks |
ユーザー | kotatsugame |
提出日時 | 2021-07-02 22:08:19 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 567 bytes |
コンパイル時間 | 766 ms |
コンパイル使用メモリ | 77,800 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-14 02:46:51 |
合計ジャッジ時間 | 1,974 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 43 |
コンパイルメッセージ
main.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 7 | main() | ^~~~
ソースコード
#include<iostream> #include<vector> #include<algorithm> using namespace std; int N; int dp[1001]; main() { cin>>N; vector<pair<int,int> >A(N); vector<int>S(N); for(int i=0;i<N;i++) { cin>>A[i].first>>A[i].second; S[i]=A[i].second; } sort(A.begin(),A.end(),[](pair<int,int>l,pair<int,int>r){return l.first+l.second<r.first+r.second;}); for(int i=1;i<=N;i++)dp[i]=2e9; for(int i=0;i<N;i++) { for(int j=i;j>=0;j--)if(dp[j]<=A[i].second) { dp[j+1]=min(dp[j+1],dp[j]+A[i].first); } } int ans=N; while(dp[ans]==(int)2e9)ans--; cout<<ans<<endl; }