Submission #24351

#TimeUsernameProblemLanguageResultExecution timeMemory
24351jiaqiyangLong Distance Coach (JOI17_coach)C++14
71 / 100
2000 ms19720 KiB
#include <cstdio>
#include <tuple>
#include <vector>
#include <algorithm>

typedef long long i64;

const int N = 200000 + 10;

i64 t;
int n, m, w;

i64 s[N], d[N];
int c[N];

void init() {
  i64 x;
  scanf("%lld%d%d%d%lld", &x, &n, &m, &w, &t);
  for (int i = 1; i <= n; ++i) scanf("%lld", &s[i]);
  s[++n] = x;
  static std::pair<i64, int> info[N];
  for (int i = 1; i <= m; ++i) scanf("%lld%d", &info[i].first, &info[i].second);
  std::sort(info + 1, info + m + 1);
  for (int i = 1; i <= m; ++i) std::tie(d[i], c[i]) = info[i];
}

int main() {
  init();
  static std::vector<i64> pool[N];
  for (int i = 1; i <= n; ++i) {
    i64 x = s[i] / t;
    int y = std::lower_bound(d + 1, d + m + 1, s[i] % t) - d - 1;
    pool[y].push_back(x);
  }
  static i64 f[N], sum[N];
  for (int i = 1; i <= m; ++i) sum[i] = sum[i - 1] + c[i];
  f[0] = (s[n] + t - 1) / t * w;
  for (int i = 1; i <= m; ++i) {
    f[i] = f[i - 1] + (s[n] - d[i] + t - 1) / t * w;
    for (auto k : pool[i])
      for (int j = 0; j < i; ++j)
        f[i] = std::min(f[i], f[j] + k * w * (i - j) + sum[i] - sum[j]);
  }
  printf("%lld\n", f[m]);
  return 0;
}

Compilation message (stderr)

coach.cpp: In function 'void init()':
coach.cpp:18:46: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%d%d%d%lld", &x, &n, &m, &w, &t);
                                              ^
coach.cpp:19:52: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   for (int i = 1; i <= n; ++i) scanf("%lld", &s[i]);
                                                    ^
coach.cpp:22:80: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   for (int i = 1; i <= m; ++i) scanf("%lld%d", &info[i].first, &info[i].second);
                                                                                ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...