#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};
ll 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';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
456 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
456 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
456 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
456 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |