답안 #1060582

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1060582 2024-08-15T17:56:15 Z MilosMilutinovic 코알라 (JOI13_koala) C++14
100 / 100
75 ms 22992 KB
#include <bits/stdc++.h>

using namespace std;

const int N = (int) (6e6);

const long long inf = (long long) -1.0001e18;

int root, ch[N][2], tsz;

long long mx[N];

void Modify(int& x, int l, int r, int i, long long v) {
  if (!x) {
    x = ++tsz;
    mx[x] = inf;
  }
  if (l == r) {
    mx[x] = max(mx[x], v);
    return;
  }
  int mid = (l + r) >> 1;
  if (i <= mid) {
    Modify(ch[x][0], l, mid, i, v);
  } else {
    Modify(ch[x][1], mid + 1, r, i, v);
  }
  mx[x] = inf;
  for (int c = 0; c < 2; c++) {
    if (ch[x][c] > 0) {
      mx[x] = max(mx[x], mx[ch[x][c]]);
    }
  }
}

long long Query(int x, int l, int r, int ll, int rr) {
  if (ll <= l && r <= rr) {
    return x == 0 ? inf : mx[x];
  }
  int mid = (l + r) >> 1;
  if (rr <= mid) {
    return Query(ch[x][0], l, mid, ll, rr);
  } else if (ll > mid) {
    return Query(ch[x][1], mid + 1, r, ll, rr);
  } else {
    return max(Query(ch[x][0], l, mid, ll, rr), Query(ch[x][1], mid + 1, r, ll, rr));
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int k, m, d, a, n;
  cin >> k >> m >> d >> a >> n;
  vector<int> t(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> t[i] >> b[i];
  }
  vector<long long> dp(n, inf);
  for (int i = 0; i < n; i++){
    dp[i] = -((t[i] - k + d - 1) / d) * 1LL * a + b[i];
    int md = (t[i] % d);
    dp[i] = max(dp[i], Query(root, 0, d, md, d) - (t[i] / d) * 1LL * a + b[i]);
    if (md > 0) {
      dp[i] = max(dp[i], Query(root, 0, d, 0, md - 1) - (t[i] / d + 1) * 1LL * a + b[i]);
    }
    Modify(root, 0, d, md, dp[i] + (t[i] / d) * 1LL * a);
  }
  long long res = inf;
  res = -((m - k + d - 1) / d) * 1LL * a;
  for (int i = 0; i < n; i++) {
    res = max(res, dp[i] - ((m - t[i] + d - 1) / d) * 1LL * a);
  }
  cout << res << '\n';
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 2 ms 752 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 3948 KB Output is correct
2 Correct 28 ms 3676 KB Output is correct
3 Correct 10 ms 2652 KB Output is correct
4 Correct 22 ms 3904 KB Output is correct
5 Correct 13 ms 2396 KB Output is correct
6 Correct 8 ms 1628 KB Output is correct
7 Correct 17 ms 2908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 7252 KB Output is correct
2 Correct 75 ms 11716 KB Output is correct
3 Correct 73 ms 16212 KB Output is correct
4 Correct 70 ms 22992 KB Output is correct
5 Correct 38 ms 6740 KB Output is correct
6 Correct 27 ms 5424 KB Output is correct