Submission #8503338


Source Code Expand

  //shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 
const ll inf = (ll)(1e9);
vector<pll> a;
ll n;
ll dp[3001][3001];

ll recurse(ll idx, ll rem) {
  if(idx == n or rem <= 0) return 0;
  ll &ans = dp[idx][rem]; 
  if(ans != -1) return ans;
  ans = 0;
  ans = a[idx].ss + recurse(idx + 1, rem - a[idx].ff);
  ans = max(ans, recurse(idx+1, rem));
  return ans;
}
int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  ll t;
  cin >> n >> t;
  a.resize(n);
  for(ll i = 0; i < n; i++) {
    cin >> a[i].ff >> a[i].ss;
  }
  sort(all(a));
  memset(dp, -1, sizeof dp);
  ll ans = -inf;
  for(ll i = 0; i < n; i++) {
    ans = max(ans, a[i].ss + recurse(i+1, t - a[i].ff));
  }
  cout << ans << endl;
  return 0;
} //good night.

Submission Info

Submission Time
Task E - All-you-can-eat
User shan61916
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1157 Byte
Status AC
Exec Time 150 ms
Memory 70784 KiB

Judge Result

Set Name Sample All after_contest
Score / Max Score 0 / 0 500 / 500 0 / 0
Status
AC × 4
AC × 31
AC × 1
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
after_contest after_contest_01
Case Name Status Exec Time Memory
after_contest_01 AC 19 ms 70656 KiB
corner_01 AC 19 ms 70656 KiB
corner_02 AC 19 ms 70656 KiB
corner_03 AC 25 ms 70656 KiB
corner_04 AC 19 ms 70656 KiB
corner_05 AC 21 ms 70656 KiB
corner_06 AC 20 ms 70656 KiB
corner_07 AC 28 ms 70656 KiB
hand_01 AC 19 ms 70656 KiB
hand_02 AC 19 ms 70656 KiB
max_01 AC 150 ms 70784 KiB
max_02 AC 149 ms 70784 KiB
max_03 AC 20 ms 70784 KiB
max_04 AC 20 ms 70784 KiB
max_05 AC 89 ms 70784 KiB
max_06 AC 94 ms 70784 KiB
max_07 AC 90 ms 70784 KiB
max_08 AC 94 ms 70784 KiB
random_01 AC 37 ms 70784 KiB
random_02 AC 28 ms 70784 KiB
random_03 AC 56 ms 70656 KiB
random_04 AC 27 ms 70656 KiB
random_05 AC 34 ms 70656 KiB
random_06 AC 76 ms 70784 KiB
random_07 AC 75 ms 70784 KiB
random_08 AC 27 ms 70656 KiB
random_09 AC 58 ms 70656 KiB
random_10 AC 62 ms 70656 KiB
sample_01 AC 19 ms 70656 KiB
sample_02 AC 19 ms 70656 KiB
sample_03 AC 19 ms 70656 KiB
sample_04 AC 19 ms 70656 KiB