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;
using ll = long long;
// n, m <= 2000
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
ll x, n, m, w, t;
cin >> x >> n >> m >> w >> t;
ll s[n+2], ans = (x + t) / t * w;
array<ll, 2> a[m+1];
for (int i = 1; i <= n; ++i) cin >> s[i];
s[n+1] = x;
sort(s+1, s+n+1);
for (int i = 1; i <= m; ++i) {
cin >> a[i][0] >> a[i][1];
ans += (x - a[i][0] + t) / t * w;
}
sort(a+1, a+m+1);
for (int i = 1; i <= n+1; ++i) {
int p = 0;
for (int j = 1; j <= m; ++j) {
if (a[j][0] < s[i] % t) p = j;
}
array<ll, 2> op = {0, p+1};
__int128 S = 0;
for (int j = p; j >= 1; --j) {
if (!a[j][0]) continue;
S += a[j][1];
S -= (x - (s[i] / t * t) - a[j][0] + t) / t * w;
op = min({S, j}, op);
}
ans += op[0];
for (int j = p; j >= op[1]; --j) a[j][0] = 0;
}
cout << ans << '\n';
}
Compilation message (stderr)
coach.cpp: In function 'int main()':
coach.cpp:32:23: warning: narrowing conversion of 'S' from '__int128' to 'long long int' [-Wnarrowing]
32 | op = min({S, j}, op);
| ^
# | 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... |