結果
問題 | No.1583 Building Blocks |
ユーザー |
👑 ![]() |
提出日時 | 2021-07-02 21:58:42 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 994 bytes |
コンパイル時間 | 1,152 ms |
コンパイル使用メモリ | 83,604 KB |
最終ジャッジ日時 | 2025-01-22 16:00:14 |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 43 |
ソースコード
#include <iostream>#include <vector>#include <algorithm>using namespace std;using ll = long long;using ull = unsigned long long;#define rep(i,n) for(int i=0; i<(n); i++)const ull MOD = 1000000007;const ll INF = MOD * MOD;int N;vector<pair<ll,ll>> SW;vector<ll> dp;int main(){cin >> N;SW.resize(N);rep(i,N){int w,s; cin >> w >> s;SW[i] = {s,w};}sort(SW.begin(),SW.end(),[](pair<int,int> l, pair<int,int> r)->bool{ll lx = min(l.first, r.first - l.second);ll rx = min(r.first, l.first - r.second);return lx < rx;});dp.assign(N+1,-INF);dp[0] = INF;rep(i,N){int w,s; cin >> w >> s;for(int k=i; k>=0; k--){dp[k+1] = max(dp[k+1],min(dp[k]-SW[i].second,SW[i].first));}}int ans = 0;rep(i,dp.size()) if(dp[i] >= 0) ans = i;cout << ans << endl;return 0;}struct ios_do_not_sync{ios_do_not_sync(){ios::sync_with_stdio(false);cin.tie(nullptr);}} ios_do_not_sync_inst;