結果
| 問題 | No.1583 Building Blocks |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-07-03 14:09:49 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 22 ms / 2,000 ms |
| コード長 | 648 bytes |
| 記録 | |
| コンパイル時間 | 769 ms |
| コンパイル使用メモリ | 71,568 KB |
| 実行使用メモリ | 74,524 KB |
| 最終ジャッジ日時 | 2024-09-14 02:51:27 |
| 合計ジャッジ時間 | 2,955 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 43 |
ソースコード
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N = 3e3+10,mod = 1e9+7;
LL f[N][N];
struct Node{
LL a,b;
bool operator<(const Node &A)const{
return a+b<A.a+A.b;
}
}a[N];
int main(){
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d%d",&a[i].a,&a[i].b);
}
sort(a+1,a+1+n);
memset(f,0x3f,sizeof f);
f[0][0]=0;
LL INF = f[1][1];
int ans=0;
for(int i=1;i<=n;i++){
f[i][0]=0;
for(int j=1;j<=i;j++){
f[i][j]=min(f[i-1][j],f[i][j]);
if(a[i].b>=f[i-1][j-1]){
f[i][j]=min(f[i][j],f[i-1][j-1]+a[i].a);
ans=max(ans,j);
}
}
}
cout<<ans;
return 0;
}