結果
問題 |
No.54 Happy Hallowe'en
|
ユーザー |
![]() |
提出日時 | 2015-05-19 18:24:56 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 162 ms / 5,000 ms |
コード長 | 1,227 bytes |
コンパイル時間 | 1,351 ms |
コンパイル使用メモリ | 160,764 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-15 17:13:06 |
合計ジャッジ時間 | 3,019 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
#include <bits/stdc++.h> #define rep(i, n) for (int (i) = 0; (i) < (int)(n); (i)++) const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, 1, 0, -1}; using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int, int> pii; const int MAXN = 10010; struct present { int v; int t; present() {} present(int v, int t) : v(v), t(t) {} bool operator<(const present& rhs) const { return v+t < rhs.v+rhs.t; } }; present p[MAXN]; bool dp[2][2*MAXN]; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; for (int i = 0; i < N; i++) { int v, t; cin >> v >> t; p[i] = present(v, t); } sort(p, p+N); memset(dp, 0, sizeof(dp)); dp[0][0] = true; for (int i = 0; i < N; i++) { int cur = i%2; int tar = cur^1; for (int t = 0; t <= MAXN; t++) { if (!dp[cur][t]) continue; dp[tar][t] = true; int tmp = t+p[i].v; if (t < p[i].t) dp[tar][tmp] = true; } } int ans = 0; for (int i = 0; i < 2*MAXN; i++) { if (dp[0][i] || dp[1][i]) ans = i; } cout << ans << endl; return 0; }