結果
| 問題 | 
                            No.54 Happy Hallowe'en
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2014-10-31 02:18:23 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 102 ms / 5,000 ms | 
| コード長 | 977 bytes | 
| コンパイル時間 | 638 ms | 
| コンパイル使用メモリ | 66,864 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-10-15 17:10:01 | 
| 合計ジャッジ時間 | 1,832 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 19 | 
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int INF = 1 << 28;
const int dp_size = 10010;
int N;
vector<pair<int, int>> house;
int dp[dp_size];
bool comp(pair<int, int> a, pair<int, int> b) {
    return (b.second - a.first) > (a.second - b.first);
}
int main(){
    cin >> N;
    
    for(int i=0;i<N;i++){
        int V, T;
        cin >> V >> T;
    
        house.push_back(make_pair(T, V));
    }
    
    sort(house.begin(), house.end(), comp);
    for(int i=0;i<dp_size;i++)dp[i] = -INF;
    dp[0] = 0;
    
    for(int i=0;i<N;i++){
        int T = house[i].first;
        int V = house[i].second;
        
        for(int t=T-1;t>=0;t--)if(dp[t] != -INF){
            int nt = min(t + V, 10000);
            dp[nt] = max(dp[nt], dp[t] + V);
        }
    }
    
    int res = -INF;
    for(int t=0;t<=10000;t++)res = max(res, dp[t]);
 
    cout << res << endl;
    return 0;
}