#include <bits/stdc++.h>
#define int long long
using namespace std;
const int NS = (int)2e5 + 4;
int x, n, m, w, t;
int r[NS];
int s[NS];
vector<int> peo[NS];
int dp[NS], vala[NS], valb[NS];
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> x >> n >> m >> w >> t;
for(int i = 1; i <= n; ++i){
cin >> s[i];
}
++n; s[n] = x;
for(int i = 1; i <= m; ++i){
peo[i].resize(2);
cin >> peo[i][0] >> peo[i][1];
}
sort(s + 1, s + n + 1, [&](int&x, int&y){return x % t < y % t;});
sort(peo + 1, peo + m + 1);
int pp = 0;
for(int i = 1; i <= n; ++i){
while(pp + 1 <= m && peo[pp + 1][0] < s[i] % t){
++pp;
}
r[i] = pp;
}
auto eat = [&](int all, int me)->int{
if(all >= me) return (all - me) / t + 1;
return 0;
};
int nodie = 0;
for(int j = 1; j <= m; ++j){
nodie += w * eat(x, peo[j][0]);
}
int ans = nodie;
for(int i = 1; i <= n; ++i){
dp[i] = (int)1e18;
for(int k = 1; k <= r[i]; ++k){
vala[k] = w * eat(x, peo[k][0]);
valb[k] = peo[k][1] + w * eat(s[i] / t * t, peo[k][0]);
}
int pos = r[i];
int valasum = 0, mn = (int)1e18, bma = 0;
for(int j = i - 1; j >= 0; --j){
while(pos > r[j]){
valasum += vala[pos];
bma += valb[pos] - vala[pos];
mn = min(mn, bma);
--pos;
}
dp[i] = min(dp[i], dp[j] + valasum + mn);
}
int nval = dp[i];
for(int j = r[i] + 1; j <= m; ++j){
nval += w * eat(x, peo[j][0]);
}
ans = min(ans, nval);
}
ans += w * eat(x, 0);
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4948 KB |
Output is correct |
2 |
Correct |
4 ms |
4948 KB |
Output is correct |
3 |
Correct |
4 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
4 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
5040 KB |
Output is correct |
9 |
Correct |
4 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
5028 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
4 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
4 ms |
4948 KB |
Output is correct |
17 |
Correct |
4 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
4 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
4 ms |
4948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4948 KB |
Output is correct |
2 |
Correct |
4 ms |
4948 KB |
Output is correct |
3 |
Correct |
4 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
4 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
5040 KB |
Output is correct |
9 |
Correct |
4 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
5028 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
4 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
4 ms |
4948 KB |
Output is correct |
17 |
Correct |
4 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
4 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
4 ms |
4948 KB |
Output is correct |
23 |
Correct |
4 ms |
4948 KB |
Output is correct |
24 |
Correct |
4 ms |
4948 KB |
Output is correct |
25 |
Correct |
3 ms |
4948 KB |
Output is correct |
26 |
Correct |
5 ms |
5032 KB |
Output is correct |
27 |
Correct |
3 ms |
4948 KB |
Output is correct |
28 |
Correct |
6 ms |
5032 KB |
Output is correct |
29 |
Correct |
4 ms |
4948 KB |
Output is correct |
30 |
Correct |
4 ms |
5068 KB |
Output is correct |
31 |
Correct |
4 ms |
4948 KB |
Output is correct |
32 |
Correct |
5 ms |
5032 KB |
Output is correct |
33 |
Correct |
3 ms |
4948 KB |
Output is correct |
34 |
Correct |
3 ms |
4948 KB |
Output is correct |
35 |
Correct |
4 ms |
4968 KB |
Output is correct |
36 |
Correct |
3 ms |
4948 KB |
Output is correct |
37 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4948 KB |
Output is correct |
2 |
Correct |
4 ms |
4948 KB |
Output is correct |
3 |
Correct |
4 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
4 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
5040 KB |
Output is correct |
9 |
Correct |
4 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
5028 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
4 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
4 ms |
4948 KB |
Output is correct |
17 |
Correct |
4 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
4 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
4 ms |
4948 KB |
Output is correct |
23 |
Correct |
4 ms |
4948 KB |
Output is correct |
24 |
Correct |
4 ms |
4948 KB |
Output is correct |
25 |
Correct |
3 ms |
4948 KB |
Output is correct |
26 |
Correct |
5 ms |
5032 KB |
Output is correct |
27 |
Correct |
3 ms |
4948 KB |
Output is correct |
28 |
Correct |
6 ms |
5032 KB |
Output is correct |
29 |
Correct |
4 ms |
4948 KB |
Output is correct |
30 |
Correct |
4 ms |
5068 KB |
Output is correct |
31 |
Correct |
4 ms |
4948 KB |
Output is correct |
32 |
Correct |
5 ms |
5032 KB |
Output is correct |
33 |
Correct |
3 ms |
4948 KB |
Output is correct |
34 |
Correct |
3 ms |
4948 KB |
Output is correct |
35 |
Correct |
4 ms |
4968 KB |
Output is correct |
36 |
Correct |
3 ms |
4948 KB |
Output is correct |
37 |
Correct |
3 ms |
4948 KB |
Output is correct |
38 |
Correct |
49 ms |
5224 KB |
Output is correct |
39 |
Correct |
50 ms |
5220 KB |
Output is correct |
40 |
Correct |
71 ms |
5224 KB |
Output is correct |
41 |
Correct |
50 ms |
5204 KB |
Output is correct |
42 |
Correct |
50 ms |
5204 KB |
Output is correct |
43 |
Correct |
39 ms |
5192 KB |
Output is correct |
44 |
Correct |
69 ms |
5232 KB |
Output is correct |
45 |
Correct |
50 ms |
5220 KB |
Output is correct |
46 |
Correct |
52 ms |
5208 KB |
Output is correct |
47 |
Correct |
57 ms |
5216 KB |
Output is correct |
48 |
Correct |
72 ms |
5232 KB |
Output is correct |
49 |
Correct |
62 ms |
5216 KB |
Output is correct |
50 |
Correct |
53 ms |
5196 KB |
Output is correct |
51 |
Correct |
53 ms |
5208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4948 KB |
Output is correct |
2 |
Correct |
4 ms |
4948 KB |
Output is correct |
3 |
Correct |
4 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
4 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
5040 KB |
Output is correct |
9 |
Correct |
4 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
5028 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
4 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
4 ms |
4948 KB |
Output is correct |
17 |
Correct |
4 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
4 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
4 ms |
4948 KB |
Output is correct |
23 |
Correct |
4 ms |
4948 KB |
Output is correct |
24 |
Correct |
4 ms |
4948 KB |
Output is correct |
25 |
Correct |
3 ms |
4948 KB |
Output is correct |
26 |
Correct |
5 ms |
5032 KB |
Output is correct |
27 |
Correct |
3 ms |
4948 KB |
Output is correct |
28 |
Correct |
6 ms |
5032 KB |
Output is correct |
29 |
Correct |
4 ms |
4948 KB |
Output is correct |
30 |
Correct |
4 ms |
5068 KB |
Output is correct |
31 |
Correct |
4 ms |
4948 KB |
Output is correct |
32 |
Correct |
5 ms |
5032 KB |
Output is correct |
33 |
Correct |
3 ms |
4948 KB |
Output is correct |
34 |
Correct |
3 ms |
4948 KB |
Output is correct |
35 |
Correct |
4 ms |
4968 KB |
Output is correct |
36 |
Correct |
3 ms |
4948 KB |
Output is correct |
37 |
Correct |
3 ms |
4948 KB |
Output is correct |
38 |
Correct |
49 ms |
5224 KB |
Output is correct |
39 |
Correct |
50 ms |
5220 KB |
Output is correct |
40 |
Correct |
71 ms |
5224 KB |
Output is correct |
41 |
Correct |
50 ms |
5204 KB |
Output is correct |
42 |
Correct |
50 ms |
5204 KB |
Output is correct |
43 |
Correct |
39 ms |
5192 KB |
Output is correct |
44 |
Correct |
69 ms |
5232 KB |
Output is correct |
45 |
Correct |
50 ms |
5220 KB |
Output is correct |
46 |
Correct |
52 ms |
5208 KB |
Output is correct |
47 |
Correct |
57 ms |
5216 KB |
Output is correct |
48 |
Correct |
72 ms |
5232 KB |
Output is correct |
49 |
Correct |
62 ms |
5216 KB |
Output is correct |
50 |
Correct |
53 ms |
5196 KB |
Output is correct |
51 |
Correct |
53 ms |
5208 KB |
Output is correct |
52 |
Execution timed out |
2055 ms |
20136 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |