Submission #1055342

# Submission time Handle Problem Language Result Execution time Memory
1055342 2024-08-12T17:42:32 Z juicy 코알라 (JOI13_koala) C++17
80 / 100
31 ms 8408 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

#define int long long

const int N = 2e5 + 5;
const long long inf = 1e18;

int k, m, d, a, n;
int t[N], b[N];
long long ft[2][N], dp[N];

void upd(long long *s, int i, long long x) {
  for (; i < N; i += i & -i) {
    s[i] = max(s[i], x);
  }
}

long long qry(long long *s, int i) {
  long long res = -inf;
  for (; i; i -= i & -i) {
    res = max(res, s[i]);
  }
  return res;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  cin >> k >> m >> d >> a >> n;
  t[0] = k, t[n + 1] = m;
  vector<int> comp = {k % d, m % d};
  for (int i = 1; i <= n; ++i) {
    cin >> t[i] >> b[i];
    comp.push_back(t[i] % d);
  }
  sort(comp.begin(), comp.end());
  comp.erase(unique(comp.begin(), comp.end()));
  for (auto it : {0, 1}) {
    fill(ft[it] + 1, ft[it] + N, -inf);
  }
  for (int i = 0; i <= n + 1; ++i) {
    int p = lower_bound(comp.begin(), comp.end(), t[i] % d) - comp.begin() + 1;
    if (i) {
      dp[i] = max(qry(ft[0], p), qry(ft[1], N - p)) - (long long) (t[i] / d) * a + b[i];
    }
    upd(ft[0], p + 1, dp[i] + (long long) (t[i] / d - 1) * a);
    upd(ft[1], N - p, dp[i] + (long long) (t[i] / d) * a);
  }
  cout << dp[n + 1];
  return 0;
}

// WTF??
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Runtime error 2 ms 4956 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 22 ms 8408 KB Output is correct
2 Correct 21 ms 8408 KB Output is correct
3 Correct 11 ms 7768 KB Output is correct
4 Correct 21 ms 8252 KB Output is correct
5 Correct 13 ms 7644 KB Output is correct
6 Correct 8 ms 7268 KB Output is correct
7 Correct 15 ms 8320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 8224 KB Output is correct
2 Correct 31 ms 8404 KB Output is correct
3 Correct 28 ms 8404 KB Output is correct
4 Correct 23 ms 8408 KB Output is correct
5 Correct 20 ms 7644 KB Output is correct
6 Correct 14 ms 7388 KB Output is correct