結果
問題 |
No.54 Happy Hallowe'en
|
ユーザー |
![]() |
提出日時 | 2020-05-08 11:53:50 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 134 ms / 5,000 ms |
コード長 | 698 bytes |
コンパイル時間 | 1,659 ms |
コンパイル使用メモリ | 173,780 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-03 09:48:24 |
合計ジャッジ時間 | 3,133 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { int N; vector<pair<int, int>> V; cin >> N; for (int i = 0; i < N; i++) { int a, b; cin >> a >> b; V.push_back({a, b}); } sort(V.begin(), V.end(), [](pair<int, int> x, pair<int, int> y) { return x.first + x.second < y.first + y.second; }); int dp[10010] = {}; dp[0] = 1; int ans = 0; for (auto& p : V) { for (int x = 10000; x >= 0; x--) { if (dp[x] && x < p.second) { ans = max(ans, x + p.first); if (x + p.first <= 10000) dp[x + p.first] = 1; } } } cout << ans << endl; }