Submission #8480451


Source Code Expand

Copy
#include <cmath>
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>

int main(){
  long long N,T;
  std::cin >> N >> T;
  std::vector<std::tuple<long long, long long>> AB_arr;
  for(int i = 0; i < N; i++){
    long long A,B;
    std::cin >> A >> B;
    AB_arr.emplace_back(A,B);
  }

  std::sort(AB_arr.begin(), AB_arr.end());

  long long dp[3001][3001] = {};

  for(int i = 0; i < N; i++){
    long long A,B;
    std::tie(A,B) = AB_arr[i];
    for(int j = 0; j < T; j++){
      if(j-A < 0){
        dp[i+1][j] = dp[i][j];
      }else{
        dp[i+1][j] = std::max(dp[i][j], B+dp[i][j-A]);
      }
    }
  }

  long long tmax = dp[N][T-1];
  long long bmax = 0;
  for(int i = N-1; i >= 0; i--){
    bmax = std::max(bmax, std::get<1>(AB_arr[i]));
    tmax = std::max(tmax, dp[i][T-1]+bmax);
  }

  std::cout << tmax << std::endl;

  return 0;
}

Submission Info

Submission Time
Task E - All-you-can-eat
User tkmtSo
Language C++14 (GCC 5.4.1)
Score 500
Code Size 872 Byte
Status AC
Exec Time 33 ms
Memory 70656 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 4
AC × 31
Set Name Test Cases
Sample sample_01, sample_02, sample_03, sample_04
All corner_01, corner_02, corner_03, corner_04, corner_05, corner_06, corner_07, hand_01, hand_02, max_01, max_02, max_03, max_04, max_05, max_06, max_07, max_08, random_01, random_02, random_03, random_04, random_05, random_06, random_07, random_08, random_09, random_10, sample_01, sample_02, sample_03, sample_04
Case Name Status Exec Time Memory
corner_01 AC 20 ms 70656 KB
corner_02 AC 21 ms 70656 KB
corner_03 AC 22 ms 70656 KB
corner_04 AC 19 ms 70656 KB
corner_05 AC 20 ms 70656 KB
corner_06 AC 19 ms 70656 KB
corner_07 AC 22 ms 70656 KB
hand_01 AC 19 ms 70656 KB
hand_02 AC 19 ms 70656 KB
max_01 AC 31 ms 70656 KB
max_02 AC 31 ms 70656 KB
max_03 AC 29 ms 70656 KB
max_04 AC 30 ms 70656 KB
max_05 AC 32 ms 70656 KB
max_06 AC 32 ms 70656 KB
max_07 AC 33 ms 70656 KB
max_08 AC 33 ms 70656 KB
random_01 AC 22 ms 70656 KB
random_02 AC 21 ms 70656 KB
random_03 AC 23 ms 70656 KB
random_04 AC 20 ms 70656 KB
random_05 AC 20 ms 70656 KB
random_06 AC 25 ms 70656 KB
random_07 AC 25 ms 70656 KB
random_08 AC 20 ms 70656 KB
random_09 AC 23 ms 70656 KB
random_10 AC 24 ms 70656 KB
sample_01 AC 19 ms 70656 KB
sample_02 AC 19 ms 70656 KB
sample_03 AC 19 ms 70656 KB
sample_04 AC 19 ms 70656 KB