Submission #217422

# Submission time Handle Problem Language Result Execution time Memory
217422 2020-03-29T15:16:30 Z Just_Solve_The_Problem 코알라 (JOI13_koala) C++14
100 / 100
136 ms 6516 KB
#include <bits/stdc++.h>

#define ll long long
#define ok puts("ok");

using namespace std;

const int N = (int)1e5 + 7;

int k, m, d, a, n;
int t[N], b[N];
ll dp[N];

vector <int> vec;

int getpos(int x) {
  return lower_bound(vec.begin(), vec.end(), x) - vec.begin();
}

ll tree[4 * N];

void build(int v = 1, int l = 0, int r = vec.size() - 1) {
  if (l == r) {
    tree[v] = -1e18;
    return ;
  }
  int mid = (l + r) >> 1;
  build(v + v, l, mid);
  build(v + v + 1, mid + 1, r);
  tree[v] = -1e18;
}

void upd(int pos, ll val, int v = 1, int l = 0, int r = vec.size() - 1) {
  if (l == r) {
    tree[v] = max(tree[v], val);
    return ;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid) {
    upd(pos, val, v + v, l, mid);
  } else {
    upd(pos, val, v + v + 1, mid + 1, r);
  }
  tree[v] = max(tree[v + v], tree[v + v + 1]);
}

ll get(int l, int r, int v = 1, int tl = 0, int tr = vec.size() - 1) {
  if (tl > r || tr < l) return -1e18;
  if (l <= tl && tr <= r) return tree[v];
  int mid = (tl + tr) >> 1;
  return max(get(l, r, v + v, tl, mid), get(l, r, v + v + 1, mid + 1, tr));
}

main() {
  scanf("%d %d %d %d %d", &k, &m, &d, &a, &n);
  t[0] = k;
  vec.push_back(k % d);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &t[i], &b[i]);
    vec.push_back(t[i] % d);
  }
  t[n + 1] = m;
  vec.push_back(t[n + 1] % d);
  sort(vec.begin(), vec.end());
  vec.resize(unique(vec.begin(), vec.end()) - vec.begin());
  build();
  upd(getpos(t[0] % d), t[0] / d * 1ll * a);
  for (int i = 1; i <= n + 1; i++) {
//    dp[i] = -1e18;
//    for (int j = 0; j < i; j++) {
//      dp[i] = max(dp[i], dp[j] - (t[i] - t[j] + d - 1) / d * 1ll * a);
//    }
//    dp[i] += b[i];
    ll mx = -1e18;
    mx = get(getpos(t[i] % d), vec.size() - 1);
    mx = max(mx, get(0, getpos(t[i] % d) - 1) - a);
    dp[i] = b[i] - t[i] / d * 1ll * a + mx;
    upd(getpos(t[i] % d), dp[i] + t[i] / d * 1ll * a);
  }
  cout << dp[n + 1];
}
/*
0 10 4 10 2
3 10
8 5
*/

Compilation message

koala.cpp:54:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
koala.cpp: In function 'int main()':
koala.cpp:55:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d %d %d", &k, &m, &d, &a, &n);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
koala.cpp:59:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &t[i], &b[i]);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 2420 KB Output is correct
2 Correct 62 ms 4076 KB Output is correct
3 Correct 35 ms 2932 KB Output is correct
4 Correct 70 ms 4332 KB Output is correct
5 Correct 38 ms 2804 KB Output is correct
6 Correct 25 ms 1780 KB Output is correct
7 Correct 34 ms 3312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 129 ms 3444 KB Output is correct
2 Correct 136 ms 6384 KB Output is correct
3 Correct 133 ms 6404 KB Output is correct
4 Correct 116 ms 6516 KB Output is correct
5 Correct 86 ms 3828 KB Output is correct
6 Correct 61 ms 3316 KB Output is correct