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 i64 = long long;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
i64 _X, n, m, w, t;
std::cin >> _X >> n >> m >> w >> t;
std::vector<i64> a(n + 2);
std::map<i64, i64> end_map, cnt_end;
for (int i = 1; i <= n; i++) {
std::cin >> a[i];
}
a[n + 1] = _X;
std::sort(a.begin(), a.end());
for (int i = 1; i <= n + 1; i++) {
if (!end_map.count(a[i] % t)) {
end_map[a[i] % t] = a[i];
if (i != n + 1)
cnt_end[a[i] % t]++;
}
}
std::vector<std::pair<i64, i64>> p(m);
std::set<std::pair<i64, i64>> s;
for (int i = 0; i < m; i++) {
std::cin >> p[i].first >> p[i].second;
s.insert({p[i].first, p[i].second});
}
std::sort(p.begin(), p.end());
i64 total = w * (_X / t + 1 - cnt_end[0]);
for (int i = 0; i < m; i++) {
total += w * ((_X - p[i].first) / t + 1 - cnt_end[p[i].first]);
}
for (int i = 1; i <= n + 1; i++) {
i64 cost = 0;
int best = 0;
i64 bestcost = 0;
i64 cur = a[i] % t - 1;
i64 curcur = cur;
int done = 0;
//~ std::cout << a[i] << ": " << a[i] % t << "\n";
while (curcur > 0) {
auto it = s.upper_bound({curcur + 1, -1});
if (it == s.begin()) break;
it--;
done++;
cost += it->second;
cost -= w * ((_X - (a[i] - a[i] % t + it->first)) / t + 1 - cnt_end[it->first]);
//~ std::cout << "_" << it->first << " " << (_X - (a[i] - a[i] % t + it->first)) << " got us " << ((_X - (a[i] - a[i] % t + it->first)) / t + 1 - cnt_end[it->first]) << "\n";
if (bestcost > cost) {
bestcost = cost;
best = done;
}
curcur = it->first - 1;
}
//~ std::cout << best << " :: " << bestcost << "\n\n";
total += bestcost;
while (best--) {
auto it = s.upper_bound({cur + 1, -1});
it--;
s.erase(it);
}
cnt_end[a[i] % t]--;
}
std::cout << total << "\n";
return 0;
}
# | 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... |