Submission #66774255


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define LagaKar ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ook order_of_key   //number of elements less than k
#define fbo find_by_order  //k th element (0 index)
#define nline endl
#define YES cout<<"YES"<<nline
#define NO cout<<"NO"<<nline
#define Yes cout<<"Yes"<<nline
#define No cout<<"No"<<nline
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#define precise(ans)  cout<<fixed<<setprecision(15)<<ans
#define fo(i,n) for(ll i=0;i<n;i++)
#define Fo(i,k,n) for(ll i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define Tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define Sz(x) ((ll)(x).size())
#define All(x) x.begin(), x.end()
#define Allr(x) x.rbegin(), x.rend()
#define MAX(x) *max_element(All(x))
#define MIN(x) *min_element(All(x))
#define SUM(x) accumulate(All(x), 0LL)
#define CNT(x) __builtin_popcountll(x)
//##################################################################################################################
typedef long long ll; typedef unsigned long long ull; typedef long double lld;
typedef pair<ll, ll>  pl;   typedef vector<ll>  vl;typedef vector<vl>  vvl; 
typedef vector<pl>  vpl;    template <typename T> using prq_mx  = priority_queue<T>; 
template <typename T> using prq_mn = priority_queue<T, vector<T>, greater<T>>;
//------------------------------------------------------------------------------------------------------------
template <typename T> using o_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T, typename R> using o_map = tree<T, R, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using o_multiset = tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<class Fun> class y_combinator_result {
    Fun fun_;
public:
    template<class T> explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}
    template<class ...Args> decltype(auto) operator()(Args &&...args) { return fun_(std::ref(*this), std::forward<Args>(args)...); }
};
template<class Fun> decltype(auto) y_combinator(Fun &&fun) { return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun)); }

//********************************************************************************************************************
#ifdef hydracody
    #include </home/anurag/Desktop/cpc/debug.h>
#else
#define debug(x)
#endif
//------------------------------------------------------------------------------------------------------------
const double eps=1e-9;const ll INF=(ll)1e9;const ll inf64=2e18;const ll INF64=9e18;
#define PI 3.1415926535897932384626
#define MOD 998244353
#define MOD1 1000000007
#define MOD2 1000000009
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
ll lcm(ll a, ll b){return (a / gcd(a, b)) * b;}
ll power(ll x,ll y, ll p){if(y==0)return 1;ll res = 1;x = x % p;if (x == 0) return 0;while (y > 0){if (y & 1)res = (res*x) % p;y = y>>1;x = (x*x) % p;}return res;}
ll pinv(ll a, ll m){ return power(a, m - 2, m); }
 ll logceil(ll x){ll s=0;while(x>0){s++;x=x/2;}return s;}
ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}
ll mod_div(ll a, ll b, ll m) {a = a % m; b = b % m; return (mod_mul(a, pinv(b, m), m) + m) % m;}  //only for prime m
ll phin(ll n) {ll number = n; if (n % 2 == 0) {number /= 2; while (n % 2 == 0) n /= 2;} for (ll i = 3; i <= sqrt(n); i += 2) {if (n % i == 0) {while (n % i == 0)n /= i; number = (number / i * (i - 1));}} if (n > 1)number = (number / n * (n - 1)) ; return number;} //O(sqrt(N))
ll getRandomNumber(ll l, ll r) {return uniform_int_distribution<ll>(l, r)(rng);} 
void starter(ll t) {cout << "Case #" << t << ": ";}
void starter1(ll t) {cerr << "Case #" << t << ": ";}
void compress(vector<ll>& vs){sort(vs.begin(),vs.end());vs.resize(unique(vs.begin(), vs.end()) - vs.begin());}
/////////////////////////////////////////////////////////////////////////////////////////////////
// **Stay calm ,Believe in YOURSELF,Never give UP
// **Not Everyday is Yours



ll rec(ll l,ll m,vvl& dp,vl& aa,vl& bb){
  if(l<0)return 0;
  // cout<<l<<" "<<m<<nline;
  if(dp[l][m]!=-1)return dp[l][m];
  ll ans=bb[l]+rec(l-1,m,dp,aa,bb);
  // cout<<l<<" "<<m<<" "<<ans<<nline;
  if(aa[l]<=m)ans=min(ans,rec(l-1,m-aa[l],dp,aa,bb));
  return dp[l][m]=ans;
}
void  chal(){
  // Bellmanford();
  ll n,h,m;
  cin>>n>>h>>m;
  vl aa(n),bb(n);
  fo(i,n){
    cin>>aa[i]>>bb[i];
  }
  vvl dp(n,vl(h+1,-1));

  auto dek=[&](ll mid)->bool{
    bool ans=rec(mid,h,dp,aa,bb)<=m;
    // cout<<mid<<' '<<ans<<" "<<rec(mid,h,dp,aa,bb)<<nline;
    return ans;
  };

  ll s=0,e=n-1,ans=0;
  while(s<=e){
    ll mid=s+(e-s)/2;
    if(dek(mid)){
      ans=mid+1;
      s=mid+1;
    }else e=mid-1;
  }
  cout<<ans<<nline;
































  


}

 

 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int32_t main() {
  LagaKar;
#ifdef hydracody
  freopen("input.txt", "r", stdin); freopen("output1.txt", "w", stdout); freopen("error.txt", "w", stderr);
#endif
  ll  t; t = 1;
  // cin>>t;
  for (ll i = 1; i <= t; i++) {
    // starter(i);
    chal();
  } 
  return 0;
}
/*
cmd->g++ code1.cpp  ./a.out
*/

Submission Info

Submission Time
Task E - Battles in a Row
User Hydracody
Language C++ 20 (gcc 12.2)
Score 450
Code Size 6188 Byte
Status AC
Exec Time 177 ms
Memory 73956 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 450 / 450
Status
AC × 3
AC × 40
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt, random_36.txt, random_37.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
random_01.txt AC 57 ms 41352 KiB
random_02.txt AC 65 ms 47080 KiB
random_03.txt AC 60 ms 28460 KiB
random_04.txt AC 16 ms 17096 KiB
random_05.txt AC 35 ms 24288 KiB
random_06.txt AC 22 ms 13388 KiB
random_07.txt AC 45 ms 43500 KiB
random_08.txt AC 74 ms 52252 KiB
random_09.txt AC 75 ms 32508 KiB
random_10.txt AC 26 ms 25876 KiB
random_11.txt AC 65 ms 45336 KiB
random_12.txt AC 63 ms 29764 KiB
random_13.txt AC 7 ms 7328 KiB
random_14.txt AC 33 ms 16828 KiB
random_15.txt AC 107 ms 57276 KiB
random_16.txt AC 22 ms 22688 KiB
random_17.txt AC 32 ms 17180 KiB
random_18.txt AC 16 ms 15464 KiB
random_19.txt AC 27 ms 27852 KiB
random_20.txt AC 41 ms 29116 KiB
random_21.txt AC 69 ms 29744 KiB
random_22.txt AC 15 ms 15596 KiB
random_23.txt AC 38 ms 19876 KiB
random_24.txt AC 55 ms 27984 KiB
random_25.txt AC 1 ms 3624 KiB
random_26.txt AC 1 ms 3572 KiB
random_27.txt AC 2 ms 4564 KiB
random_28.txt AC 1 ms 3444 KiB
random_29.txt AC 1 ms 3452 KiB
random_30.txt AC 1 ms 3620 KiB
random_31.txt AC 145 ms 73956 KiB
random_32.txt AC 30 ms 73864 KiB
random_33.txt AC 145 ms 73940 KiB
random_34.txt AC 177 ms 73900 KiB
random_35.txt AC 176 ms 73860 KiB
random_36.txt AC 175 ms 73896 KiB
random_37.txt AC 177 ms 73848 KiB
sample_01.txt AC 1 ms 3464 KiB
sample_02.txt AC 1 ms 3596 KiB
sample_03.txt AC 1 ms 3504 KiB