Submission #1055324

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

using namespace std;

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

const int N = 1e5 + 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;
}

int 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;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Runtime error 1 ms 604 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 22 ms 6108 KB Output is correct
2 Correct 20 ms 5592 KB Output is correct
3 Correct 11 ms 4832 KB Output is correct
4 Correct 21 ms 5852 KB Output is correct
5 Correct 13 ms 4776 KB Output is correct
6 Correct 7 ms 3808 KB Output is correct
7 Correct 13 ms 5096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 5852 KB Output is correct
2 Correct 30 ms 5852 KB Output is correct
3 Correct 27 ms 5844 KB Output is correct
4 Correct 28 ms 5844 KB Output is correct
5 Correct 18 ms 4828 KB Output is correct
6 Correct 15 ms 4288 KB Output is correct