This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int INF = (int) 1e9 + 1e6;
const ll LINF = (ll) 1e18 + 1e9;
const ll MOD = (ll) 1e9 + 7;
#define sz(x) (int) (x).size()
#define mp(x, y) make_pair(x, y)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lb(s, t, x) (int) (lower_bound(s, t, x) - s)
#define ub(s, t, x) (int) (upper_bound(s, t, x) - s)
#define rep(i, f, t) for (auto i = f; i < t; ++(i))
#define per(i, f, t) for (auto i = (f); i >= (t); --(i))
ll power(ll x, ll y, ll mod = MOD) {
if (y == 0) {
return 1;
}
if (y & 1) {
return power(x, y - 1, mod) * x % mod;
} else {
ll tmp = power(x, y / 2, mod);
return tmp * tmp % mod;
}
}
template<typename A, typename B> bool mini(A &x, const B &y) {
if (y < x) {
x = y;
return true;
}
return false;
}
template<typename A, typename B> bool maxi(A &x, const B &y) {
if (x < y) {
x = y;
return true;
}
return false;
}
void add(ll &x, ll y) {
x += y;
if (x >= MOD) x -= MOD;
if (x < 0) x += MOD;
}
void run();
#define TASK ""
int main() {
#ifdef LOCAL
if (strlen(TASK) > 0) {
cerr << "Reminder: you are using file i/o, filename: " TASK "!" << endl << endl;
}
#endif
#ifndef LOCAL
if (strlen(TASK)) {
freopen(TASK ".in", "r", stdin);
freopen(TASK ".out", "w", stdout);
}
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#endif
cout << fixed << setprecision(12);
run();
return 0;
}
// == SOLUTION == //
const int N = (int) 2e5 + 123;
int n, m;
ll x, w, t;
ll s[N];
pair<ll, ll> p[N];
ll d[N], c[N];
int r[N];
vector<int> what[N];
ll dp[N];
struct Line {
ll k, b;
ll val(ll x) const {
return k * x + b;
}
};
ll div_up(ll x, ll y) {
if (y < 0) {
x = -x;
y = -y;
}
if (x < 0) {
return x / y;
} else {
return (x + y - 1) / y;
}
}
ll inter(const Line &a, const Line &b) {
return div_up(b.b - a.b, a.k - b.k);
}
struct CHT {
vector<Line> lines;
vector<ll> points;
void add(const Line &l) {
while (sz(points) && inter(l, lines.back()) <= points.back()) {
points.pop_back();
lines.pop_back();
}
if (sz(lines)) {
points.pb(inter(l, lines.back()));
}
lines.pb(l);
}
ll get(ll x) {
int pos = (int) (upper_bound(all(points), x) - points.begin());
return lines[pos].val(x);
}
};
CHT cht;
void run() {
cin >> x >> n >> m >> w >> t;
rep(i, 1, n + 1) {
cin >> s[i];
}
s[n + 1] = x;
rep(i, 1, m + 1) {
cin >> p[i].first >> p[i].second;
}
sort(p + 1, p + m + 1);
rep(i, 1, m + 1) {
d[i] = p[i].first;
c[i] = p[i].second;
}
rep(i, 0, n + 1) {
r[i] = (int) (lower_bound(d, d + m + 1, s[i + 1] % t) - d) - 1;
what[r[i]].pb(i);
}
dp[0] = s[n + 1] / t * w + w;
cht.add({0, dp[0]});
ll fee = 0;
rep(i, 1, m + 1) {
fee += c[i];
dp[i] = dp[i - 1] + (s[n + 1] - d[i]) / t * w + w;
for (int id : what[i]) {
ll cnt = s[id + 1] / t;
mini(dp[i], cht.get(cnt * w) + fee + i * cnt * w);
}
cht.add({-i, dp[i] - fee});
}
cout << dp[m] << "\n";
}
Compilation message (stderr)
coach.cpp: In function 'int main()':
coach.cpp:67:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(TASK ".in", "r", stdin);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
coach.cpp:68:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(TASK ".out", "w", stdout);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |