結果

問題 No.54 Happy Hallowe'en
ユーザー r_dream0r_dream0
提出日時 2017-03-01 21:19:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 280 ms / 5,000 ms
コード長 801 bytes
コンパイル時間 897 ms
コンパイル使用メモリ 77,556 KB
実行使用メモリ 376,560 KB
最終ジャッジ日時 2023-09-03 17:08:35
合計ジャッジ時間 3,500 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 64 ms
94,548 KB
testcase_05 AC 97 ms
138,888 KB
testcase_06 AC 133 ms
187,692 KB
testcase_07 AC 183 ms
259,024 KB
testcase_08 AC 221 ms
312,496 KB
testcase_09 AC 280 ms
376,560 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 272 ms
282,496 KB
testcase_13 AC 273 ms
356,688 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int dp[10001][10001];
int main() {
  vector<pair<int, pair<int,int>>> input;
  int N;
  cin >> N;
  input.resize(N);
  for(int i = 0; i < input.size(); i++) {
    cin >> input[i].second.second >> input[i].second.first;
    input[i].first = input[i].second.second + input[i].second.first;
  }
  sort(input.begin(), input.end());
  dp[0][0] = 1;
  int ans = 0;
  for(int i = 0; i < N; i++) {
    for(int j = 0; j <= 10000; j++) {
      if(dp[i][j]) {
        int next = j + input[i].second.second;
        if(j < input[i].second.first) {
          ans = max(ans, next);
          if(next <= 10000) {
            dp[i + 1][next] = 1;
          }
        }
        dp[i + 1][j] = 1;
      }
    }
  }
  cout << ans << endl;
}
0