Submission #217420

# Submission time Handle Problem Language Result Execution time Memory
217420 2020-03-29T15:15:13 Z Just_Solve_The_Problem 코알라 (JOI13_koala) C++14
0 / 100
128 ms 3436 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 * 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 * a + mx;
    upd(getpos(t[i] % d), dp[i] + t[i] / d * 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 Incorrect 6 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 69 ms 2416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 128 ms 3436 KB Output isn't correct
2 Halted 0 ms 0 KB -