結果
| 問題 |
No.1583 Building Blocks
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-07-09 15:35:45 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 6 ms / 2,000 ms |
| コード長 | 839 bytes |
| コンパイル時間 | 863 ms |
| コンパイル使用メモリ | 71,496 KB |
| 実行使用メモリ | 11,212 KB |
| 最終ジャッジ日時 | 2024-09-14 02:52:55 |
| 合計ジャッジ時間 | 1,946 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 43 |
ソースコード
#include <iostream>
#include <algorithm>
using namespace std;
pair<long long, long long> p[1009];
long long d[1009][1009], inf = 1e18;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n; cin >> n;
for (int i = 1; i <= n; i++) {
cin >> p[i].second >> p[i].first;
p[i].first += p[i].second;
}
sort(p + 1, p + n + 1);
for (int i = 1; i <= n; i++)
d[0][i] = inf;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= n; j++) {
d[i][j] = d[i - 1][j];
if (j && d[i - 1][j - 1] + p[i].second <= p[i].first) d[i][j] = min(d[i][j], d[i - 1][j - 1] + p[i].second);
}
}
int ans = 0;
for (int i = n; i >= 1; i--)
if (d[n][i] != inf) {
ans = i;
break;
}
cout << ans << '\n';
return 0;
}