Problem:
夜店(Night Market)
太郎くんは，JOI 神社で開かれる夏祭りに行くことにした．
JOI 神社に向かう道に沿って，
N
個の夜店が開かれている．それぞれの夜店には，1 から
N
までの番号が順番についており，遊んだ時の楽しさと遊ぶのにかかる時間がそれぞれ整数で決まっている．夜店
i
で遊んだ時の楽しさは
A
i
で，夜店
i
で遊ぶのにかかる時間は
B
i
である．
また，夏祭りのイベントとして花火大会があり，時刻
S
に最も大きな花火が打ち上げられる．太郎くんはこの最も大きな花火を見たいと思っている．
太郎くんは夜店と花火の両方を楽しむために，夏祭りに到着する時刻0 から夏祭りが終わる時刻
T
までの予定を立てることにした．
太郎くんは夜店の中から
k
個(1 ≤
k
≤
N
) の夜店を選び，それぞれに対して訪れる時刻を整数で決める．同じ夜店を2 度選ぶことはできない．選ばれた夜店の番号を小さい順に
y
1
,
y
2
, ...
y
k
とし，夜店
y
i
を訪れる時刻を
x
y
i
とすると，太郎くんは夜店
y
i
で時刻
x
y
i
から時刻
x
y
i
+
B
y
i
まで遊ぶ．
太郎くんは夜店の番号の小さい順に遊び，同時に2 つの夜店では遊べない．また，夜店と夜店の間の移
動にかかる時間は無視できる．
時刻
T
を超えると夏祭りが終わるので，夜店で遊ぶことはできない．また，夜店で遊んでいる間は花火を見ることはできない．ただし，時刻
S
がある夜店で遊び始める時刻や遊び終わる時刻であった場合は，太郎くんは花火を見ることができるものとする．
すなわち，予定は以下の条件を満たしていなければならない．
y
1
<
y
2
< ... <
y
k
x
y
1
,
x
y
2
, ...
x
y
k
は整数．
0 ≤
x
y
1
<
x
y
1
+
B
y
1
≤
x
y
2
<
x
y
2
+
B
y
2
≤ ... ≤
x
y
k
<
x
y
k
+
B
y
k
≤
T
x
y
i
<
S
<
x
y
i
+
B
y
i
となるような
i
は存在しない．
選ばれた夜店の楽しさ
A
y
1
,
A
y
2
, ...
A
y
k
の合計を
M
とする．太郎くんは
M
ができるだけ大きくなるように予定を立てたいと思っている．
課題
N
個の夜店の情報と時刻
S
,
T
が与えられた時，
M
の最大値を求めるプログラムを作成せよ．
制限
1 ≤
N
≤ 3000     夜店の数
1 ≤
T
≤ 3000     夏祭りが終わる時刻
0 ≤
S
≤
T
最も大きな花火が打ち上げられる時刻
0 ≤
A
i
≤ 100000 (= 10
5
)     夜店i で遊んだ時の楽しさ
1 ≤
B
i
≤ 3000     夜店
i
で遊ぶのにかかる時間
入力
標準入力から以下の入力を読み込め．
入力の1 行目には整数
N
,
T
,
S
が空白を区切りとして書かれており，夜店の数が
N
個，夏祭りが終わる時刻が
T
，最も大きな花火が打ち上げられる時刻が
S
であることを表す．
続く
N
行には夜店の情報が書かれている．入力の
i
+ 1 (1 ≤
i
≤
N
) 行目には整数
A
i
,
B
i
が空白を区切りとして書かれており，夜店
i
で遊んだ時の楽しさが
A
i
で，夜店
i
で遊ぶのにかかる時間が
B
i
であることを表す．
また，すべての入力において，１つ以上の予定を立てられることが保証されている．
出力
標準出力に，
M
の最大値を表す整数を1 行で出力せよ．
採点基準
採点用データのうち，
配点の10%分については，
N
≤ 20 を満たす．
配点の20%分については，
S
= 0 を満たす．
配点の30%分については，これら2 つの条件の少なくとも一方を満たす．また，これら2 つの条件の両方を満たすような採点用データはない．
入出力例
入力例 1
5 20 14
8 9
2 4
7 13
6 3
5 8
出力例 1
16
この例において，
夜店1 を時刻0 に訪れ，
夜店2 を時刻9 に訪れ，
夜店4 を時刻14 に訪れるような予定を立てると，
M
を最も大きくすることができる．
このとき，
M
= 8 + 2 + 6 = 16 である．
問題文と自動審判に使われるデータは、
情報オリンピック日本委員会
が作成し公開している問題文と採点用テストデータです。

Submitted solutions:

code_snippet: #include<iostream>
using namespace std;

const int max_n = 3010;  // 最大アイテム数
const int max_t = 3010;  // 最大時間

int main()
{
    int N, T, S;
    while(cin >> N >> T >> S){
        int A[max_n], B[max_n];
        
        // 各アイテムの価値と時間を読み込み
        for(int i = 0; i < N; ++i){
            cin >> A[i] >> B[i];
        }
        
        static int dp[max_n][max_t];
        
        // dp配列を初期化
        for(int i = 0; i <= N; ++i){
            for(int j = 0; j <= T; ++j){
                dp[i][j] = 0;
            }
        }
        
        // 動的計画法による計算
        for(int i = 0; i < N; ++i){
            for(int j = 0; j <= T; ++j){
                // アイテムiを選ばない場合
                dp[i+1][j] = max(dp[i+1][j], dp[i][j]);

                // アイテムiを選ぶ場合、時間jにアイテムを追加した場合の更新
                dp[i][j+1] = max(dp[i][j+1], dp[i][j]);

                // アイテムiを選ぶ場合、時間帯制約を確認
                if(j + B[i] <= T){
                    if(!(j < S && S < j + B[i])){
                        dp[i+1][j + B[i]] = max(dp[i+1][j + B[i]], dp[i][j] + A[i]);
                    }
                }
            }
        }
        
        // 最終的に得られる最大の価値を出力
        cout << dp[N][T] << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 38744
final_rank: 5

code_snippet: #line 1 "/opt/library/template.hpp"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using i64 = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;

template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'000'001'000;
template <>
constexpr ll infty<ll> = ll(infty<int>) * infty<int> * 2;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * infty<ll>;
template <>
constexpr double infty<double> = infty<ll>;
template <>
constexpr long double infty<long double> = infty<ll>;
#define inf infty<ll>

using pi = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vector<ll>>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;

#define vv(type, name, h, ...) \
  vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...)   \
  vector<vector<vector<type>>> name( \
      h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)       \
  vector<vector<vector<vector<type>>>> name( \
      a, vector<vector<vector<type>>>(       \
             b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))

#define rep1(a) for (ll _ = 0; _ < (ll)(a); ++_)
#define rep2(i, a) for (ll i = 0; i < (ll)(a); ++i)
#define rep3(i, a, b) for (ll i = a; i < (ll)(b); ++i)
#define rep4(i, a, b, c) for (ll i = a; i < (ll)(b); i += (c))
#define rrep1(a) for (ll i = (a)-1; i >= (ll)(0); --i)
#define rrep2(i, a) for (ll i = (a)-1; i >= (ll)(0); --i)
#define rrep3(i, a, b) for (ll i = (b)-1; i >= (ll)(a); --i)
#define rrep4(i, a, b, c) for (ll i = (b)-1; i >= (ll)(a); i -= (c))
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)

#define all(x) (x).begin(),(x).end()
#define len(x) (ll)(x.size())
#define elif else if
#define bit(x, i) (((x)>>(i))&1)

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define stoi stoll
#define abs llabs

#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) \
  sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()

ll popcnt(ll x) { return __builtin_popcountll(x); }
ll popcnt(u64 x) { return __builtin_popcountll(x); }
ll popcnt_mod_2(ll x) { return __builtin_parityll(x); }
ll popcnt_mod_2(u64 x) { return __builtin_parityll(x); }
ll topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
ll topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
ll lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
ll lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }

template <typename T>
T floor(T a, T b) {
  return a / b - (a % b && (a ^ b) < 0);
}
template <typename T>
T ceil(T x, T y) {
  return floor(x + y - 1, y);
}
template <typename T>
T bmod(T x, T y) {
  return x - y * floor(x, y);
}
template <typename T>
pair<T, T> divmod(T x, T y) {
  T q = floor(x, y);
  return {q, x - q * y};
}

template<typename T> T SUM(const vector<T> &A) {
  T s = 0; for (auto &&a: A) s += a;
  return s;
}

template <typename T>
T POP(queue<T> &que) {
  T a = que.front();
  que.pop();
  return a;
}
template <typename T>
T POP(deque<T> &que) {
  T a = que.front();
  que.pop_front();
  return a;
}
template <typename T>
T POP(pq<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(pqg<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(vc<T> &que) {
  T a = que.back();
  que.pop_back();
  return a;
}

template <typename F>
ll binary_search(F check, ll ok, ll ng, bool check_ok = true) {
  if (check_ok) assert(check(ok));
  while (abs(ok - ng) > 1) {
    auto x = (ng + ok) / 2;
    (check(x) ? ok : ng) = x;
  }
  return ok;
}
template <typename F>
f128 binary_search_real(F check, f128 ok, f128 ng, ll iter = 100) {
  rep(iter) {
    f128 x = (ok + ng) / 2;
    (check(x) ? ok : ng) = x;
  }
  return (ok + ng) / 2;
}

// ? は -1
vc<int> s_to_vi(const string &S, char first_char) {
  vc<int> A(S.size());
  rep(i, S.size()) { A[i] = (S[i] != '?' ? S[i] - first_char : -1); }
  return A;
}

template <typename T, typename U>
vc<T> cumsum(vc<U> &A, ll off = 1) {
  ll N = A.size();
  vc<T> B(N + 1);
  rep(i, N) { B[i + 1] = B[i] + A[i]; }
  if (off == 0) B.erase(B.begin());
  return B;
}

// stable sort
template <typename T>
vi argsort(const vector<T> &A) {
  vi ids(len(A));
  iota(all(ids), 0);
  sort(all(ids),
       [&](ll i, ll j) { return (A[i] == A[j] ? i < j : A[i] < A[j]); });
  return ids;
}

// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vi &I) {
  vc<T> B(len(I));
  rep(i, len(I)) B[i] = A[I[i]];
  return B;
}

template<typename T> inline bool chmax(T &a, T b) {return ((a<b)?(a=b,true):(false));}
template<typename T> inline bool chmin(T &a, T b) {return ((a>b)?(a=b,true):(false));}

inline void wt(const char c) { cout << c; }
inline void wt(const string s) { cout << s; }
inline void wt(const char *s) { cout << s; }

template <typename T>
void wt_integer(T x) {
  if (x < 0) { cout << (i64)(x); }
  else { cout << (u64)(x); }
}
template <typename T>
void wt_real(T x) {
  cout << fixed << setprecision(15) << (long double)(x);
}

inline void wt(int x) { wt_integer(x); }
inline void wt(ll x) { wt_integer(x); }
inline void wt(i128 x) { wt_integer(x); }
inline void wt(u32 x) { wt_integer(x); }
inline void wt(u64 x) { wt_integer(x); }
inline void wt(u128 x) { wt_integer(x); }
inline void wt(double x) { wt_real(x); }
inline void wt(long double x) { wt_real(x); }
inline void wt(f128 x) { wt_real(x); }

template <class T, class U>
void wt(const pair<T, U> val) {
  wt(val.first); wt(' '); wt(val.second);
}
template <size_t N = 0, typename T>
void wt_tuple(const T t) {
  if constexpr (N < std::tuple_size<T>::value) {
    if constexpr (N > 0) { wt(' '); }
    const auto x = std::get<N>(t);
    wt(x);
    wt_tuple<N + 1>(t);
  }
}
template <class... T>
void wt(tuple<T...> tpl) {
  wt_tuple(tpl);
}
template <class T, size_t S>
void wt(const array<T, S> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}
template <class T>
void wt(const vector<T> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}

void print() { wt('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
  wt(head);
  if (sizeof...(Tail)) wt(' ');
  print(forward<Tail>(tail)...);
}

void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
void onez(bool t = 1) { print(t ? 1 : 0); }
#define endl '\n'
#define dump(x) {cerr << #x " = " << x << '\n';}
#line 2 "main.cpp"

int solve();
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  while (!solve()) {break;}
  return 0;
}

int solve() {
  ll N, T, S;
  cin >> N >> T >> S;
  vi A(N+1), B(N+1);
  rep(i, 1, N+1) cin >> A[i] >> B[i];
  vv(ll, dp, N+1, S+1, 0);
  vv(ll, dp2, N+2, T-S+1, 0);
  rep(i, 1, N+1) {
    rep(j, 1, S+1) {
      dp[i][j] = dp[i-1][j];
      if (j-B[i] < 0) continue;
      chmax(dp[i][j], dp[i-1][j-B[i]] + A[i]);
    }
  }
  rrep(i, 1, N+1) {
    rep(j, S+1, T+1) {
      ll k = j - S;
      dp2[i][k] = dp2[i+1][k];
      if (k-B[i] < 0) continue;
      chmax(dp2[i][k], dp2[i+1][k-B[i]] + A[i]);
    }
  }
  ll ans = 0;
  rep(i, N) {
    chmax(ans, dp[i][S] + MAX(dp2[i+1]));
  }
  print(ans);
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 73836
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
#define all(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)

int main() {
    ll N,T,S;
    cin>>N>>T>>S;
    vvll DP(N+1,vll(T+1,-1e18));
    DP[0][0]=0;
    rep(i,N){
        ll A,B;
        cin>>A>>B;
        for(ll t=0;t<=T;t++){
            DP[i+1][t]=max(DP[i+1][t],DP[i][t]);
            if(t!=T)DP[i+1][t+1]=max(DP[i+1][t+1],DP[i+1][t]);
            if(t+B<=T){
                if(t<S&&S<t+B)continue;
                DP[i+1][t+B]=max(DP[i+1][t+B],DP[i][t]+A);
            }
        }
    }
    //cout<<DP[2][13]<<endl;
    ll an=0;
    rep(t,T+1)an=max(an,DP[N][t]);
    cout<<an<<endl;
}
accuracy: 1
time_ms: 40
memory_kb: 73564
final_rank: 12

code_snippet: #define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<random>
#include<bitset>
#include<cassert>
using namespace std;
typedef long long ll;
const int mod=998244353;
const int dx[]={1,0,0,-1},dy[]={0,1,-1,0};
int dp[3001][3001];
int main(){
	int n,t,s,a[3000],b[3000];
	cin>>n>>t>>s;
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i];
	for(int i=0;i<n;i++){
		for(int j=0;j<=t;j++){
			dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
			if(j<s&&s<j+b[i]){
				if(s+b[i]<=t)
					dp[i+1][s+b[i]]=max(dp[i+1][s+b[i]],dp[i][j]+a[i]);
			}else
				if(j+b[i]<=t)
					dp[i+1][j+b[i]]=max(dp[i+1][j+b[i]],dp[i][j]+a[i]);
		}
	}
	cout<<*max_element(dp[n],dp[n]+t+1)<<endl;
}
accuracy: 1
time_ms: 10
memory_kb: 38652
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
const long long MOD1 = 1000000007;
const long long MOD2 = 998244353;
typedef long long ll;
//typedef int ll;
typedef pair<ll, ll> P;
const long long INF = 1e10;
template <typename T>
void input_arr(vector<T>& A, ll N) {
	for (ll i = 0; i < N; i++) {
		cin >> A[i];
	}
}
template <typename T, typename Q>
void input_arr(vector<pair<T, Q>>& A, ll N) {
	for (ll i = 0; i < N; i++) {
		cin >> A[i].first >> A[i].second;
	}
}
template <typename T>
void input_arr(vector<vector<T>>& A, ll H, ll W) {
	for (ll i = 0; i < H; i++) {
		for (ll j = 0; j < W; j++) {
			cin >> A[i][j];
		}
	}
}
void solve() {
    ll N, T, S; cin >> N >> T >> S;
    vector<ll>A(N), B(N);
    for (ll i = 0; i < N; i++) cin >> A[i] >> B[i];
    vector<vector<ll>>DP(N + 1, vector<ll>(T + 1, 0));
    for (ll i = 0; i <= T; i++) {
        if (i >= B[0] && !(i - B[0] < S && S < i)) DP[1][i] = A[0];
    }
    for (ll i = 2; i <= N; i++) {
        for (ll j = 0; j <= T; j++) {
            if (j >= B[i - 1] && !(j - B[i - 1] < S && S < j)) DP[i][j] = max(DP[i - 1][j], DP[i - 1][j - B[i - 1]] + A[i - 1]);
            else DP[i][j] = DP[i - 1][j];
        }
    }
    ll ans = -1;
    for (ll i = 0; i <= T; i++) {
        ans = max(ans, DP[N][i]);
    }
    cout << ans << endl;
}
int main() {
    ll T=1; //cin >> T;
    while (T--) solve();
}
accuracy: 1
time_ms: 30
memory_kb: 73608
final_rank: 10

code_snippet: #include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define popcount(v) __builtin_popcount(v)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=(ll)1<<60;
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T,class U,class V>void scan(tuple<T,U,V>& p){scan(get<0>(p));scan(get<1>(p));scan(get<2>(p));}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}

int main(){
    INT(n,t,s);
    vector<array<int,2>> a(n);
    rep(i,n)in(a[i][0],a[i][1]);
    vector<int> dp(t+1,-INF);
    dp[0]=0;
    rep(i,n){
        for(int j=t-a[i][1];j>=0;j--){
            if(!(j<s&&s<j+a[i][1]))chmax(dp[j+a[i][1]],dp[j]+a[i][0]);
        }
        rep(j,t)chmax(dp[j+1],dp[j]);
    }
    out(*max_element(all(dp)));
}
accuracy: 1
time_ms: 10
memory_kb: 3604
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;
using lint = long long;
#define rep(i, n) for(int i = 0; i < int(n); i++)
void chmin(int &a, int b){ if(a > b) a = b; }
void chmax(int &a, int b){ if(a < b) a = b; }

int dp[3030][3030];

int main(){
    int n, t, s;
    cin >> n >> t >> s;
    int a[n], b[n];
    rep(i, n) cin >> a[i] >> b[i];
    
    rep(i, 3030) rep(j, 3030) dp[i][j] = 0;
    
    rep(i, n){
        rep(j, t + 1){
            chmax(dp[i + 1][j], dp[i][j]);
            if((j + b[i] <= s) || (j >= s && j + b[i] <= t)){
                chmax(dp[i + 1][j + b[i]], dp[i][j] + a[i]);
            }
            chmax(dp[i][j + 1], dp[i][j]);
        }
    }
    
    cout << *max_element(dp[n], dp[n] + t + 1) << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 39324
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
using lint = long long;
#define rep(i, n) for(int i = 0; i < int(n); i++)
void chmin(int &a, int b){ if(a > b) a = b; }
void chmax(int &a, int b){ if(a < b) a = b; }

int dp[3030][3030];

int main(){
    int n, t, s;
    cin >> n >> t >> s;
    int a[n], b[n];
    rep(i, n) cin >> a[i] >> b[i];
    
    rep(i, 3030) rep(j, 3030) dp[i][j] = 0;
    
    rep(i, n){
        rep(j, t){
            chmax(dp[i + 1][j], dp[i][j]);
            if((j + b[i] <= s) || (j >= s && j + b[i] <= t)){
                chmax(dp[i + 1][j + b[i]], dp[i][j] + a[i]);
            }
            chmax(dp[i][j + 1], dp[i][j]);
        }
    }
    
    cout << *max_element(dp[n], dp[n] + t + 1) << endl;
}
accuracy: 0.2
time_ms: 10
memory_kb: 39296
final_rank: 20

code_snippet: #include<bits/stdc++.h>
#define int long long
constexpr long long mod = 1000000007;
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define puts(x) cout << (x) << "\n"
using namespace std;
int n, t, s, a[4000], b[4000], dp[3500][3500];
signed main() {
	cin >> n >> t >> s;
	for1(i, n)cin >> a[i] >> b[i];
	for1(i, n)for1(j, t) {
		dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
		if (j >= b[i] && (j <= s || j - b[i] >= s))dp[i][j] = max(dp[i][j], dp[i - 1][j - b[i]] + a[i]);
	}
	puts(dp[n][t]);
}
accuracy: 1
time_ms: 10
memory_kb: 87436
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;

const int INF = 1<<29;
int main() {
    int N, T, S;
    cin >> N >> T >> S;
    vector<int> A(N), B(N);
    for (int i = 0; i < N; ++i) cin >> A[i] >> B[i];

    auto add = [&](vector<int> dp, int a, int b) -> vector<int> {
        for (int t = T; t >= b; --t) dp[t] = max(dp[t], dp[t-b]+a);
        return dp;
    };

    vector<vector<int>> left(N+1, vector<int>(T+1, -INF)), right = left;
    for (int t = 0; t <= T; ++t) left[0][t] = right[0][t] = 0;
    for (int i = 0; i < N; ++i) {
        left[i+1] = add(left[i], A[i], B[i]);
        right[i+1] = add(right[i], A[N-i-1], B[N-i-1]);
    }
    int res = 0;
    for (int l = 0; l <= N; ++l) {
        res = max(res, left[l][S] + right[N-l][T-S]);
        //cout << l << ": " << left[l][S] << ", " << right[N-l][T-S] << endl;
    }
    cout << res << endl;
}
accuracy: 1
time_ms: 30
memory_kb: 74048
final_rank: 14

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define stoi stoll
#define rep(i, n) for (int i = 0; i < (int)(n); i++)             // [0, b)
#define rep2(i, a, b) for (int i = (int)(a); i < (int)(b); i++)  // [a, b)
#define rep3(i, a, b) for (int i = (int)(a); i >= (int)(b); i--) // reversed [b, a] so [a, a-1, a-2, ..., b]
#define FOR(i, a) for (auto &i: a)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define SUM(x) accumulate(ALL(x), 0LL)
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
const int MOD    = 998244353;
const int MOD2   = 1000000007;
const int INF    = (int)(1e13 + 7);
const double EPS = 1e-14;
const double PI  = acos(-1);

int CEIL(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); } //ceil() for int
int mod(int a, int b) { return a >= 0 ? a % b : a - (b * CEIL(a, b)); }             //always return positive num
int pow_mod(int a, int b) {                                                         //return x^y in order(log(y))
  int res = 1;
  for (a %= MOD; b; a = a * a % MOD, b >>= 1)
    if (b & 1) res = res * a % MOD;
  return res;
}

signed main() {
  cin.tie(nullptr);
  cout.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int N, T, S;
  int A, B;
  cin >> N >> T >> S;
  vector<vector<int>> dp(N + 1, vector<int>(T + 100, 0));
  rep2(i, 1, N + 1) {
    cin >> A >> B;
    dp[i] = dp[i - 1];
    rep(j, T - B + 1) {
      if (!(j < S and S < j + B)) {
        dp[i][j + B] = max(dp[i - 1][j] + A, dp[i][j + B]);
      }
    }
  }
  cout << MAX(dp[N]) << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 39484
final_rank: 7

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define stoi stoll
#define rep(i, n) for (int i = 0; i < (int)(n); i++)             // [0, b)
#define rep2(i, a, b) for (int i = (int)(a); i < (int)(b); i++)  // [a, b)
#define rep3(i, a, b) for (int i = (int)(a); i >= (int)(b); i--) // reversed [b, a] so [a, a-1, a-2, ..., b]
#define FOR(i, a) for (auto &i: a)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define SUM(x) accumulate(ALL(x), 0LL)
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
const int MOD    = 998244353;
const int MOD2   = 1000000007;
const int INF    = (int)(1e13 + 7);
const double EPS = 1e-14;
const double PI  = acos(-1);

int CEIL(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); } //ceil() for int
int mod(int a, int b) { return a >= 0 ? a % b : a - (b * CEIL(a, b)); }             //always return positive num
int pow_mod(int a, int b) {                                                         //return x^y in order(log(y))
  int res = 1;
  for (a %= MOD; b; a = a * a % MOD, b >>= 1)
    if (b & 1) res = res * a % MOD;
  return res;
}

signed main() {
  cin.tie(nullptr);
  cout.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int N, T, S;
  int A, B;
  cin >> N >> T >> S;
  vector<vector<int>> dp(N + 1, vector<int>(T + 100, 0));
  rep2(i, 1, N + 1) {
    cin >> A >> B;
    rep(j, T + 100) {
      dp[i] = dp[i - 1];
    }
    rep(j, T - B + 1) {
      if (!(j < S and S < j + B)) {
        dp[i][j + B] = max(dp[i - 1][j] + A, dp[i][j + B]);
      }
    }
  }
  cout << MAX(dp[N]) << endl;
}
accuracy: 1
time_ms: 1650
memory_kb: 39516
final_rank: 8

code_snippet: #include <bits/stdc++.h>
#define int long long
#define stoi stoll
#define rep(i, n) for (int i = 0; i < (int)(n); i++)             // [0, b)
#define rep2(i, a, b) for (int i = (int)(a); i < (int)(b); i++)  // [a, b)
#define rep3(i, a, b) for (int i = (int)(a); i >= (int)(b); i--) // reversed [b, a] so [a, a-1, a-2, ..., b]
#define FOR(i, a) for (auto &i: a)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define SUM(x) accumulate(ALL(x), 0LL)
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
const int MOD    = 998244353;
const int MOD2   = 1000000007;
const int INF    = (int)(1e13 + 7);
const double EPS = 1e-14;
const double PI  = acos(-1);

int CEIL(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); } //ceil() for int
int mod(int a, int b) { return a >= 0 ? a % b : a - (b * CEIL(a, b)); }             //always return positive num
int pow_mod(int a, int b) {                                                         //return x^y in order(log(y))
  int res = 1;
  for (a %= MOD; b; a = a * a % MOD, b >>= 1)
    if (b & 1) res = res * a % MOD;
  return res;
}

signed main() {
  cin.tie(nullptr);
  cout.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int N, T, S;
  cin >> N >> T >> S;
  vector<vector<int>> dp(N + 1, vector<int>(T + 100, 0));
  rep2(i, 1, N + 1) {
    int A, B;
    cin >> A >> B;
    rep(j, T + 100) {
      dp[i] = dp[i - 1];
    }
    rep(j, T - B + 1) {
      if (!(j < S and S < j + B)) {
        dp[i][j + B] = max(dp[i - 1][j] + A, dp[i][j + B]);
      }
    }
  }
  cout << MAX(dp[N]) << endl;
}
accuracy: 1
time_ms: 7590
memory_kb: 75752
final_rank: 18

code_snippet: #pragma region Macros
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; --i)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'
#define overload2(_1, _2, name, ...) name
#define vec(type, name, ...) vector<type> name(__VA_ARGS__)
#define VEC(type, name, size)\
    vector<type> name(size);\
    IN(name)
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define VV(type, name, h, w)\
    vector<vector<type>> name(h, vector<type>(w));\
    IN(name)
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)\
    vector<vector<vector<vector<type>>>> name(a, vector<vector<vector<type>>>(b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))
#define fi first
#define se second
#define all(c) begin(c), end(c)
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
using namespace std;
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
#define si(c) (int)(c).size()
#define INT(...)\
    int __VA_ARGS__;\
    IN(__VA_ARGS__)
#define LL(...)\
    ll __VA_ARGS__;\
    IN(__VA_ARGS__)
#define STR(...)\
    string __VA_ARGS__;\
    IN(__VA_ARGS__)
#define CHR(...)\
    char __VA_ARGS__;\
    IN(__VA_ARGS__)
#define DBL(...)\
    double __VA_ARGS__;\
    IN(__VA_ARGS__)
int scan() { return getchar(); }
void scan(int &a) { cin >> a; }
void scan(long long &a) { cin >> a; }
void scan(char &a) { cin >> a; }
void scan(double &a) { cin >> a; }
void scan(string &a) { cin >> a; }
template <class T, class S> void scan(pair<T, S> &p) { scan(p.first), scan(p.second); }
template <class T> void scan(vector<T> &);
template <class T> void scan(vector<T> &a) {
    for(auto &i : a) scan(i);
}
template <class T> void scan(T &a) { cin >> a; }
void IN() {}
template <class Head, class... Tail> void IN(Head &head, Tail &... tail) {
    scan(head);
    IN(tail...);
}
template <class T, class S> inline bool chmax(T &a, S b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T, class S> inline bool chmin(T &a, S b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
vi iota(int n) {
    vi a(n);
    iota(all(a), 0);
    return a;
}
template <typename T> vi iota(vector<T> &a, bool greater = false) {
    vi res(a.size());
    iota(all(res), 0);
    sort(all(res), [&](int i, int j) {
        if(greater) return a[i] > a[j];
        return a[i] < a[j];
    });
    return res;
}
#define UNIQUE(x) sort(all(x)), x.erase(unique(all(x)), x.end())
template <class T> T POW(T x, int n) {
    T res = 1;
    for(; n; n >>= 1, x *= x)
        if(n & 1) res *= x;
    return res;
}
vector<pll> factor(ll x) {
    vector<pll> ans;
    for(ll i = 2; i * i <= x; i++)
        if(x % i == 0) {
            ans.push_back({i, 1});
            while((x /= i) % i == 0) ans.back().second++;
        }
    if(x != 1) ans.push_back({x, 1});
    return ans;
}
template <class T> vector<T> divisor(T x) {
    vector<T> ans;
    for(T i = 1; i * i <= x; i++)
        if(x % i == 0) {
            ans.pb(i);
            if(i * i != x) ans.pb(x / i);
        }
    return ans;
}
template <typename T> void zip(vector<T> &x) {
    vector<T> y = x;
    sort(all(y));
    for(int i = 0; i < x.size(); ++i) { x[i] = lb(y, x[i]); }
}
int popcount(ll x) { return __builtin_popcountll(x); }
int in() {
    int x;
    cin >> x;
    return x;
}
ll lin() {
    unsigned long long x;
    cin >> x;
    return x;
}
template <typename T> struct edge {
    int from, to;
    T cost;
    int id;
    edge(int to, T cost) : from(-1), to(to), cost(cost) {}
    edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
    edge(int from, int to, T cost, int id) : from(from), to(to), cost(cost), id(id) {}
    edge &operator=(const int &x) {
        to = x;
        return *this;
    }
    operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;
using Tree = vector<vector<int>>;
using Graph = vector<vector<int>>;
template <class T> using Wgraph = vector<vector<edge<T>>>;
Graph getG(int n, int m = -1, bool directed = false, int margin = 1) {
    Tree res(n);
    if(m == -1) m = n - 1;
    while(m--) {
        int a, b;
        cin >> a >> b;
        a -= margin, b -= margin;
        res[a].emplace_back(b);
        if(!directed) res[b].emplace_back(a);
    }
    return move(res);
}
template <class T> Wgraph<T> getWg(int n, int m = -1, bool directed = false, int margin = 1) {
    Wgraph<T> res(n);
    if(m == -1) m = n - 1;
    while(m--) {
        int a, b;
        T c;
        cin >> a >> b >> c;
        a -= margin, b -= margin;
        res[a].emplace_back(b, c);
        if(!directed) res[b].emplace_back(a, c);
    }
    return move(res);
}
#define i128 __int128_t
#define ull unsigned long long int
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
struct Setup_io {
    Setup_io() {
        ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
        cout << fixed << setprecision(15);
    }
} setup_io;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" :", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#define LOCAL
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#pragma endregion
//#include<atcoder/all>
//using namespace atcoder;
const ll INF = 1e18;
int main(){
    INT(n,t,s);
    vec(int,a,n);
    vec(int,b,n);
    rep(i,n)cin >> a[i] >> b[i];
    vv(ll,dp,n+1,t+1,0);
    dp[0][0] = 0;
    rep(i,n){
        rep(j,t+1){
            chmax(dp[i+1][j],dp[i][j]);
            if((j+b[i]<= s || j >= s) && j+b[i] <= t)chmax(dp[i+1][j+b[i]],dp[i][j]+a[i]);
        }
    }
    ll ret = -INF;
    rep(i,t+1)chmax(ret,dp[n][i]);
    // trace(dp);
    cout << ret << endl;
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 73544
final_rank: 9

code_snippet: #include<iostream>
#include<vector>
using namespace std;

template<typename T>
bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

int main(){
    int n, t, s;
    cin >> n >> t >> s;

    vector<int> a(n), b(n);
    for(int i = 0 ; i < n ; ++i){
        cin >> a[i] >> b[i];
    }

    vector< vector<int> > dp(n + 1, vector<int>(t + 1, 0));
    for(int i = 0 ; i < n ; ++i){
        for(int j = 0 ; j <= t ; ++j){
            chmax(dp[i + 1][j], dp[i][j]);

            if(j + 1 <= t){
                chmax(dp[i][j + 1], dp[i][j]);
            }

            if(j + b[i] <= t && (j + b[i] <= s || s <= j)){
                chmax(dp[i + 1][j + b[i]], dp[i][j] + a[i]);
            }
        }
    }

    cout << dp[n][t] << endl;

    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 38492
final_rank: 3

code_snippet: #include<bits/stdc++.h>
#define rep(i, x) for(ll i = 0; i < x; i++)
using ll = long long;
using namespace std;
ll n, W, s; ll w[345678], v[345678], dp[5000][23456];
void solve() {
	for (int i = n - 1; i >= 0; i--) {
		for (int j = 0; j <= W; j++) {
			if (j >= w[i] && (j - w[i] >= s || j <= s)) { dp[i][j] = dp[i + 1][j - w[i]] + v[i]; }
			dp[i][j] = max(dp[i][j], max(dp[i + 1][j], dp[i][j - 1]));
		}
	}
	cout << dp[0][W] << endl;
}
signed main() {
	cin >> n >> W >> s; s = W - s;
	rep(i, n) { cin >> v[i] >> w[i]; }
	solve(); return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 85652
final_rank: 16

code_snippet: #include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,T,S;
    cin >> N >> T >> S;
    vector<ll> A(N),B(N);
    for(int i=0; i<N; i++){
        cin >> A[i] >> B[i];
    }
    vector<vector<ll>> dp(N+5, vector<ll> (S+5,0));
    for(int i=0; i<N; i++){
        for(int j=0; j<=S; j++){
            chmax(dp[i+1][j],dp[i][j]);
            if(j+B[i] > S) continue;
            chmax(dp[i+1][j+B[i]], dp[i][j] + A[i]);
        }
    }
    vector<vector<ll>> dp2(N+5, vector<ll> (T-S+5,0));
    for(int i=N; i>0; i--){
        for(int j=0; j<=T-S; j++){
            chmax(dp2[i][j],dp2[i+1][j]);
            if(j+B[i-1] > T-S) continue;
            chmax(dp2[i][j+B[i-1]],dp2[i+1][j]+A[i-1]);
        }
    }
    ll ans = 0;
    for(int i=0; i<=N; i++){
        chmax(ans,dp[i][S]+dp2[i+1][T-S]);
    }
    cout << ans << enld;
    return 0;
}
accuracy: 1
time_ms: 130
memory_kb: 73920
final_rank: 15

code_snippet: #include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int n, t, s; cin >> n >> t >> s;
    vector<ll> value(n), time(n);

    rep(i,n) cin >> value[i] >> time[i];
    vector<vector<ll>> dp1(n+1, vector<ll> (s+1,0));
    vector<vector<ll>> dp2(n+1, vector<ll> ((t-s)+1,0));

    for(int i = 0; i < n; i++){
        for(int T = 0; T <= s; T++){
            if(T >= time[i]) dp1[i+1][T] = max(dp1[i][T-time[i]] + value[i],dp1[i][T]);
            else dp1[i+1][T] = dp1[i][T];
        }
    }

    for(int i = 0; i < n; i++){
        for(int T = 0; T <= t-s; T++){
            if(T >= time[n-i]) dp2[i+1][T] = max(dp2[i][T-time[n-i]] + value[n-i],dp2[i][T]);
            else dp2[i+1][T] = dp2[i][T];
        }
    }

    ll ans = 0;
    rep(i,n){
        ans = max(dp2[i][t-s] + dp1[n-i][s], ans);
    }

    cout << ans << endl;
}
accuracy: 1
time_ms: 30
memory_kb: 73656
final_rank: 11

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
const int MOD=998244353;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,t,s;cin >> n >> t >> s;
    vector<int> a(n),b(n);
    for(int i=0;i<n;i++){
        cin >> a[i] >> b[i];
    }
    vector<vector<int>> dp(t+1,vector<int>(2,-1));
    dp[0][0]=0;
    vector<vector<int>> p(t+1,vector<int>(2,-1));
    p[0][0]=0;
    if(s==0){
        dp[0][1]=0;
        p[0][1]=0;
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<=t;j++){
            for(int k=0;k<2;k++){
                if(dp[j][k]==-1){
                    continue;
                }
                chmax(p[j][k],dp[j][k]);
                if(j<=s&&k==0){
                    chmax(p[s][1],dp[j][0]);
                }
                if(j+b[i]<=t){
                    if(j+b[i]<=s&&k==0){
                        chmax(p[s][1],dp[j][0]+a[i]);
                    }
                    chmax(p[j+b[i]][k],dp[j][k]+a[i]);
                }
            }
        }
        for(int j=0;j<=t;j++){
            for(int k=0;k<2;k++){
                chmax(dp[j][k],p[j][k]);
                p[j][k]=-1;
            }
        }
    }
    int ans=0;
    for(int i=0;i<=t;i++){
        chmax(ans,dp[i][1]);
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 70
memory_kb: 3420
final_rank: 2

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
const int MOD=998244353;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,t,s;cin >> n >> t >> s;
    vector<int> a(n),b(n);
    for(int i=0;i<n;i++){
        cin >> a[i] >> b[i];
    }
    vector<vector<int>> dp(t+1,vector<int>(2,-1));
    dp[0][0]=0;
    vector<vector<int>> p(t+1,vector<int>(2,-1));
    p[0][0]=0;
    if(s==0){
        dp[0][1]=0;
        p[0][1]=0;
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<=t;j++){
            for(int k=0;k<2;k++){
                if(dp[j][k]==-1){
                    continue;
                }
                chmax(p[j][k],dp[j][k]);
                if(j<=s&&k==0){
                    chmax(p[s][k],dp[j][k]);
                }
                if(j+b[i]<=t){
                    if(j+b[i]<=s&&k==0){
                        chmax(p[s][1],dp[j][0]+a[i]);
                    }
                    chmax(p[j+b[i]][k],dp[j][k]+a[i]);
                }
            }
        }
        for(int j=0;j<=t;j++){
            for(int k=0;k<2;k++){
                chmax(dp[j][k],p[j][k]);
                p[j][k]=-1;
            }
        }
    }
    int ans=0;
    for(int i=0;i<=t;i++){
        chmax(ans,dp[i][1]);
    }
    cout << ans << endl;
}
accuracy: 0.5
time_ms: 60
memory_kb: 3372
final_rank: 19