結果

問題 No.54 Happy Hallowe'en
ユーザー krotonkroton
提出日時 2014-10-31 02:18:23
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 82 ms / 5,000 ms
コード長 977 bytes
コンパイル時間 569 ms
コンパイル使用メモリ 70,040 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-05 20:05:07
合計ジャッジ時間 1,744 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 12 ms
4,380 KB
testcase_05 AC 18 ms
4,376 KB
testcase_06 AC 26 ms
4,380 KB
testcase_07 AC 40 ms
4,376 KB
testcase_08 AC 56 ms
4,376 KB
testcase_09 AC 79 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 61 ms
4,376 KB
testcase_13 AC 82 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0