Submission #73159333


Source Code Expand

#include <bits/stdc++.h>

//#include <atcoder/all>
using namespace std;

#define lli long long int
#define REP(i, s, n) for (lli i = s; i < n; i++)
#define INF (1LL << 62)
#define mp(a, b) make_pair(a, b)
#define SORT(V) sort(V.begin(), V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) #VariableName
#define LOG1(x)                                                                \
  if (DEBUG)                                                                   \
    cout << TO_STRING(x) << "=" << x << " " << endl;
#define LOG2(x, y)                                                             \
  if (DEBUG)                                                                   \
    cout << TO_STRING(x) << "=" << x << " " << TO_STRING(y) << "=" << y << endl;
#define LOG3(x, y, z)                                                          \
  if (DEBUG)                                                                   \
    cout << TO_STRING(x) << "=" << x << " " << TO_STRING(y) << "=" << y << " " \
         << TO_STRING(z) << "=" << z << endl;
#define LOG4(w, x, y, z)                                                       \
  if (DEBUG)                                                                   \
    cout << TO_STRING(w) << "=" << w << " " << TO_STRING(x) << "=" << x << " " \
         << TO_STRING(y) << "=" << y << " " << TO_STRING(z) << "=" << z        \
         << endl;
#define LOG5(w, x, y, z, a)                                                    \
  if (DEBUG)                                                                   \
    cout << TO_STRING(w) << "=" << w << " " << TO_STRING(x) << "=" << x << " " \
         << TO_STRING(y) << "=" << y << " " << TO_STRING(z) << "=" << z << " " \
         << TO_STRING(a) << "=" << a << endl;
#define LOG6(w, x, y, z, a, b)                                                 \
  if (DEBUG)                                                                   \
    cout << TO_STRING(w) << "=" << w << " " << TO_STRING(x) << "=" << x << " " \
         << TO_STRING(y) << "=" << y << " " << TO_STRING(z) << "=" << z << " " \
         << TO_STRING(a) << "=" << a << " " << TO_STRING(b) << "=" << b        \
         << endl;

#define overload6(a, b, c, d, e, f, g, ...) g
#define LOG(...)                                                               \
  overload6(__VA_ARGS__, LOG6, LOG5, LOG4, LOG3, LOG2, LOG1)(__VA_ARGS__)

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;
}

mt19937 engine;
std::chrono::system_clock::time_point start, endTime;

#define DEBUG 0

lli dp[210][210];

void solve() {
  //  write your code here

  lli N, M, K;
  cin >> N >> M >> K;

  vector<lli> A(N), B(N);
  REP(i, 0, N) { cin >> A[i] >> B[i]; }

  REP(i, 0, 210) {
    REP(j, 0, 210) { dp[i][j] = -INF; }
  }

  dp[0][0] = 0;
  REP(i, 0, 210) { dp[i][0] = 0; }

  REP(i, 0, N) {
    REP(j, max(-1LL, i - K), i) {
      REP(k, 0, M + 1) {
        if (dp[j + 1][k] == -INF) {
          continue;
        }
        if (k + B[i] > M) {
          continue;
        }
        chmax(dp[i + 1][k + B[i]], dp[j + 1][k] + A[i]);
      }
    }
  }

  lli ans = 0;
  REP(i, 0, N + 1) {
    REP(j, 0, M + 1) { chmax(ans, dp[i][j]); }
  }
  cout << ans << endl;
}

// Generated by 2.13.0 https://github.com/kyuridenamida/atcoder-tools  (tips:
// You use the default template now. You can remove this line by using your
// custom template)
int main() {
  // Failed to predict input format

  lli N = 1;
  // cin >> N;
  while (N--)
    solve();

  return 0;
}

Submission Info

Submission Time
Task D - Merchant on the Highway
User ohuton_labo
Language C++23 (GCC 15.2.0)
Score 400
Code Size 3796 Byte
Status AC
Exec Time 6 ms
Memory 4044 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 69
Set Name Test Cases
Sample sample01.txt, sample02.txt, sample03.txt
All sample01.txt, sample02.txt, sample03.txt, in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in29.txt, in30.txt, in31.txt, in32.txt, in33.txt, in34.txt, in35.txt, in36.txt, in37.txt, in38.txt, in39.txt, in40.txt, in41.txt, in42.txt, in43.txt, in44.txt, in45.txt, in46.txt, in47.txt, in48.txt, in49.txt, in50.txt, in51.txt, in52.txt, in53.txt, in54.txt, in55.txt, in56.txt, in57.txt, in58.txt, in59.txt, in60.txt, in61.txt, in62.txt, in63.txt, in64.txt, in65.txt, in66.txt
Case Name Status Exec Time Memory
in01.txt AC 1 ms 3884 KiB
in02.txt AC 1 ms 3956 KiB
in03.txt AC 1 ms 4028 KiB
in04.txt AC 1 ms 3844 KiB
in05.txt AC 1 ms 4044 KiB
in06.txt AC 6 ms 3960 KiB
in07.txt AC 1 ms 3976 KiB
in08.txt AC 1 ms 3956 KiB
in09.txt AC 1 ms 3960 KiB
in10.txt AC 2 ms 4012 KiB
in11.txt AC 5 ms 4044 KiB
in12.txt AC 1 ms 4024 KiB
in13.txt AC 1 ms 3840 KiB
in14.txt AC 1 ms 3872 KiB
in15.txt AC 1 ms 3844 KiB
in16.txt AC 1 ms 4028 KiB
in17.txt AC 5 ms 4012 KiB
in18.txt AC 1 ms 3884 KiB
in19.txt AC 4 ms 3816 KiB
in20.txt AC 1 ms 3976 KiB
in21.txt AC 5 ms 3840 KiB
in22.txt AC 5 ms 3840 KiB
in23.txt AC 5 ms 3960 KiB
in24.txt AC 6 ms 3956 KiB
in25.txt AC 5 ms 4028 KiB
in26.txt AC 1 ms 3844 KiB
in27.txt AC 5 ms 3884 KiB
in28.txt AC 1 ms 3956 KiB
in29.txt AC 1 ms 3856 KiB
in30.txt AC 1 ms 3856 KiB
in31.txt AC 1 ms 3856 KiB
in32.txt AC 1 ms 3840 KiB
in33.txt AC 1 ms 3960 KiB
in34.txt AC 1 ms 3844 KiB
in35.txt AC 1 ms 3956 KiB
in36.txt AC 1 ms 3840 KiB
in37.txt AC 1 ms 3840 KiB
in38.txt AC 1 ms 4012 KiB
in39.txt AC 1 ms 3844 KiB
in40.txt AC 1 ms 3944 KiB
in41.txt AC 1 ms 3844 KiB
in42.txt AC 1 ms 4024 KiB
in43.txt AC 1 ms 3976 KiB
in44.txt AC 1 ms 4044 KiB
in45.txt AC 6 ms 4044 KiB
in46.txt AC 5 ms 4044 KiB
in47.txt AC 5 ms 4044 KiB
in48.txt AC 1 ms 4028 KiB
in49.txt AC 2 ms 3976 KiB
in50.txt AC 5 ms 4024 KiB
in51.txt AC 6 ms 4028 KiB
in52.txt AC 5 ms 3840 KiB
in53.txt AC 1 ms 3884 KiB
in54.txt AC 1 ms 3840 KiB
in55.txt AC 1 ms 3884 KiB
in56.txt AC 1 ms 4024 KiB
in57.txt AC 1 ms 4024 KiB
in58.txt AC 1 ms 4044 KiB
in59.txt AC 1 ms 3840 KiB
in60.txt AC 1 ms 4044 KiB
in61.txt AC 1 ms 4012 KiB
in62.txt AC 1 ms 3956 KiB
in63.txt AC 1 ms 4040 KiB
in64.txt AC 1 ms 3944 KiB
in65.txt AC 1 ms 3876 KiB
in66.txt AC 1 ms 3956 KiB
sample01.txt AC 1 ms 3944 KiB
sample02.txt AC 1 ms 4028 KiB
sample03.txt AC 1 ms 3884 KiB