// vaziat meshki-ghermeze !
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'
using namespace std;
typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
const ll Mod = 1000000007LL;
const int N = 2e5 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;
ll dp[N];
ll rif[N];
ll mn[N];
typedef pll Line;
vector< pair<ll, Line> > CHT;
ll Inter(Line A, Line B){
return (A.S - B.S) / (B.F - A.F) + ((A.S - B.S) % (B.F - A.F) > 0);
}
void Add(Line A){
while(!CHT.empty() && Inter(CHT.back().S, A) <= CHT.back().F)
CHT.pop_back();
CHT.pb({CHT.empty() ? -Inf : Inter(CHT.back().S, A), A});
}
ll Get(ll X){
int idx = upper_bound(all(CHT), pair<ll, Line>(X, pll(Inf, Inf))) - CHT.begin();
idx --;
return CHT[idx].S.F * X + CHT[idx].S.S;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll X, n, m, W, T;
cin >> X >> n >> m >> W >> T;
vector<pll> D = { {0, 0} }; // D, C
for(int i = 0; i < n; i++)
cin >> rif[i];
rif[n] = X;
int d, c;
for(int i = 0; i < m; i++){
cin >> d >> c;
D.pb({d, c});
}
sort(all(D));
for(int i = 1; i <= m; i++) D[i].S += D[i - 1].S;
memset(mn, 31, sizeof mn);
for(int i = 0; i <= n; i++){
int idx = lower_bound(all(D), pll(rif[i] % T, -1)) - D.begin();
idx --;
assert(0 <= idx);
mn[idx] = min(mn[idx], rif[i]);
}
dp[0] = ((X + T) / T) * W;
for(int i = 1; i <= m; i++){
Add({-(i - 1), dp[i - 1] - D[i - 1].S});
dp[i] = dp[i - 1] + ( 1 + ((X - D[i].F) / T) ) * W;
// debug(mn[i]);
if(mn[i] >= Inf) continue;
ll fac = mn[i] / T;
// debug(fac);
dp[i] = min(dp[i], D[i].S + i * fac * W + Get(fac * W));
}
//
// for(auto [d, c] : D) cerr << "(" << d << ", " << c << ")\n";
// for(int i = 0; i <= m; i++) cerr << dp[i] << ' ';
// cerr << '\n';
//
cout << dp[m] << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1868 KB |
Output is correct |
2 |
Correct |
1 ms |
1868 KB |
Output is correct |
3 |
Correct |
2 ms |
1868 KB |
Output is correct |
4 |
Correct |
2 ms |
1992 KB |
Output is correct |
5 |
Correct |
1 ms |
1868 KB |
Output is correct |
6 |
Correct |
1 ms |
1868 KB |
Output is correct |
7 |
Correct |
1 ms |
1868 KB |
Output is correct |
8 |
Correct |
1 ms |
1868 KB |
Output is correct |
9 |
Correct |
2 ms |
1868 KB |
Output is correct |
10 |
Correct |
2 ms |
1868 KB |
Output is correct |
11 |
Correct |
1 ms |
1868 KB |
Output is correct |
12 |
Correct |
1 ms |
1868 KB |
Output is correct |
13 |
Correct |
1 ms |
1868 KB |
Output is correct |
14 |
Correct |
2 ms |
1868 KB |
Output is correct |
15 |
Correct |
2 ms |
1868 KB |
Output is correct |
16 |
Correct |
2 ms |
1868 KB |
Output is correct |
17 |
Correct |
2 ms |
1868 KB |
Output is correct |
18 |
Correct |
2 ms |
1868 KB |
Output is correct |
19 |
Correct |
2 ms |
1868 KB |
Output is correct |
20 |
Correct |
2 ms |
1868 KB |
Output is correct |
21 |
Correct |
2 ms |
1868 KB |
Output is correct |
22 |
Correct |
2 ms |
1868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1868 KB |
Output is correct |
2 |
Correct |
1 ms |
1868 KB |
Output is correct |
3 |
Correct |
2 ms |
1868 KB |
Output is correct |
4 |
Correct |
2 ms |
1992 KB |
Output is correct |
5 |
Correct |
1 ms |
1868 KB |
Output is correct |
6 |
Correct |
1 ms |
1868 KB |
Output is correct |
7 |
Correct |
1 ms |
1868 KB |
Output is correct |
8 |
Correct |
1 ms |
1868 KB |
Output is correct |
9 |
Correct |
2 ms |
1868 KB |
Output is correct |
10 |
Correct |
2 ms |
1868 KB |
Output is correct |
11 |
Correct |
1 ms |
1868 KB |
Output is correct |
12 |
Correct |
1 ms |
1868 KB |
Output is correct |
13 |
Correct |
1 ms |
1868 KB |
Output is correct |
14 |
Correct |
2 ms |
1868 KB |
Output is correct |
15 |
Correct |
2 ms |
1868 KB |
Output is correct |
16 |
Correct |
2 ms |
1868 KB |
Output is correct |
17 |
Correct |
2 ms |
1868 KB |
Output is correct |
18 |
Correct |
2 ms |
1868 KB |
Output is correct |
19 |
Correct |
2 ms |
1868 KB |
Output is correct |
20 |
Correct |
2 ms |
1868 KB |
Output is correct |
21 |
Correct |
2 ms |
1868 KB |
Output is correct |
22 |
Correct |
2 ms |
1868 KB |
Output is correct |
23 |
Correct |
2 ms |
1868 KB |
Output is correct |
24 |
Correct |
2 ms |
1868 KB |
Output is correct |
25 |
Correct |
1 ms |
1868 KB |
Output is correct |
26 |
Correct |
1 ms |
1868 KB |
Output is correct |
27 |
Correct |
2 ms |
1868 KB |
Output is correct |
28 |
Correct |
2 ms |
1868 KB |
Output is correct |
29 |
Correct |
2 ms |
1868 KB |
Output is correct |
30 |
Correct |
2 ms |
1868 KB |
Output is correct |
31 |
Correct |
2 ms |
1868 KB |
Output is correct |
32 |
Correct |
2 ms |
1868 KB |
Output is correct |
33 |
Correct |
2 ms |
1868 KB |
Output is correct |
34 |
Correct |
2 ms |
1868 KB |
Output is correct |
35 |
Correct |
1 ms |
1868 KB |
Output is correct |
36 |
Correct |
1 ms |
1868 KB |
Output is correct |
37 |
Correct |
2 ms |
1868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1868 KB |
Output is correct |
2 |
Correct |
1 ms |
1868 KB |
Output is correct |
3 |
Correct |
2 ms |
1868 KB |
Output is correct |
4 |
Correct |
2 ms |
1992 KB |
Output is correct |
5 |
Correct |
1 ms |
1868 KB |
Output is correct |
6 |
Correct |
1 ms |
1868 KB |
Output is correct |
7 |
Correct |
1 ms |
1868 KB |
Output is correct |
8 |
Correct |
1 ms |
1868 KB |
Output is correct |
9 |
Correct |
2 ms |
1868 KB |
Output is correct |
10 |
Correct |
2 ms |
1868 KB |
Output is correct |
11 |
Correct |
1 ms |
1868 KB |
Output is correct |
12 |
Correct |
1 ms |
1868 KB |
Output is correct |
13 |
Correct |
1 ms |
1868 KB |
Output is correct |
14 |
Correct |
2 ms |
1868 KB |
Output is correct |
15 |
Correct |
2 ms |
1868 KB |
Output is correct |
16 |
Correct |
2 ms |
1868 KB |
Output is correct |
17 |
Correct |
2 ms |
1868 KB |
Output is correct |
18 |
Correct |
2 ms |
1868 KB |
Output is correct |
19 |
Correct |
2 ms |
1868 KB |
Output is correct |
20 |
Correct |
2 ms |
1868 KB |
Output is correct |
21 |
Correct |
2 ms |
1868 KB |
Output is correct |
22 |
Correct |
2 ms |
1868 KB |
Output is correct |
23 |
Correct |
2 ms |
1868 KB |
Output is correct |
24 |
Correct |
2 ms |
1868 KB |
Output is correct |
25 |
Correct |
1 ms |
1868 KB |
Output is correct |
26 |
Correct |
1 ms |
1868 KB |
Output is correct |
27 |
Correct |
2 ms |
1868 KB |
Output is correct |
28 |
Correct |
2 ms |
1868 KB |
Output is correct |
29 |
Correct |
2 ms |
1868 KB |
Output is correct |
30 |
Correct |
2 ms |
1868 KB |
Output is correct |
31 |
Correct |
2 ms |
1868 KB |
Output is correct |
32 |
Correct |
2 ms |
1868 KB |
Output is correct |
33 |
Correct |
2 ms |
1868 KB |
Output is correct |
34 |
Correct |
2 ms |
1868 KB |
Output is correct |
35 |
Correct |
1 ms |
1868 KB |
Output is correct |
36 |
Correct |
1 ms |
1868 KB |
Output is correct |
37 |
Correct |
2 ms |
1868 KB |
Output is correct |
38 |
Correct |
3 ms |
1868 KB |
Output is correct |
39 |
Correct |
3 ms |
1868 KB |
Output is correct |
40 |
Correct |
3 ms |
1868 KB |
Output is correct |
41 |
Correct |
3 ms |
1868 KB |
Output is correct |
42 |
Correct |
3 ms |
1868 KB |
Output is correct |
43 |
Correct |
3 ms |
1868 KB |
Output is correct |
44 |
Correct |
3 ms |
1868 KB |
Output is correct |
45 |
Correct |
3 ms |
1904 KB |
Output is correct |
46 |
Correct |
2 ms |
2052 KB |
Output is correct |
47 |
Correct |
2 ms |
1868 KB |
Output is correct |
48 |
Correct |
3 ms |
1868 KB |
Output is correct |
49 |
Correct |
3 ms |
1868 KB |
Output is correct |
50 |
Correct |
3 ms |
1940 KB |
Output is correct |
51 |
Correct |
3 ms |
1996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1868 KB |
Output is correct |
2 |
Correct |
1 ms |
1868 KB |
Output is correct |
3 |
Correct |
2 ms |
1868 KB |
Output is correct |
4 |
Correct |
2 ms |
1992 KB |
Output is correct |
5 |
Correct |
1 ms |
1868 KB |
Output is correct |
6 |
Correct |
1 ms |
1868 KB |
Output is correct |
7 |
Correct |
1 ms |
1868 KB |
Output is correct |
8 |
Correct |
1 ms |
1868 KB |
Output is correct |
9 |
Correct |
2 ms |
1868 KB |
Output is correct |
10 |
Correct |
2 ms |
1868 KB |
Output is correct |
11 |
Correct |
1 ms |
1868 KB |
Output is correct |
12 |
Correct |
1 ms |
1868 KB |
Output is correct |
13 |
Correct |
1 ms |
1868 KB |
Output is correct |
14 |
Correct |
2 ms |
1868 KB |
Output is correct |
15 |
Correct |
2 ms |
1868 KB |
Output is correct |
16 |
Correct |
2 ms |
1868 KB |
Output is correct |
17 |
Correct |
2 ms |
1868 KB |
Output is correct |
18 |
Correct |
2 ms |
1868 KB |
Output is correct |
19 |
Correct |
2 ms |
1868 KB |
Output is correct |
20 |
Correct |
2 ms |
1868 KB |
Output is correct |
21 |
Correct |
2 ms |
1868 KB |
Output is correct |
22 |
Correct |
2 ms |
1868 KB |
Output is correct |
23 |
Correct |
2 ms |
1868 KB |
Output is correct |
24 |
Correct |
2 ms |
1868 KB |
Output is correct |
25 |
Correct |
1 ms |
1868 KB |
Output is correct |
26 |
Correct |
1 ms |
1868 KB |
Output is correct |
27 |
Correct |
2 ms |
1868 KB |
Output is correct |
28 |
Correct |
2 ms |
1868 KB |
Output is correct |
29 |
Correct |
2 ms |
1868 KB |
Output is correct |
30 |
Correct |
2 ms |
1868 KB |
Output is correct |
31 |
Correct |
2 ms |
1868 KB |
Output is correct |
32 |
Correct |
2 ms |
1868 KB |
Output is correct |
33 |
Correct |
2 ms |
1868 KB |
Output is correct |
34 |
Correct |
2 ms |
1868 KB |
Output is correct |
35 |
Correct |
1 ms |
1868 KB |
Output is correct |
36 |
Correct |
1 ms |
1868 KB |
Output is correct |
37 |
Correct |
2 ms |
1868 KB |
Output is correct |
38 |
Correct |
3 ms |
1868 KB |
Output is correct |
39 |
Correct |
3 ms |
1868 KB |
Output is correct |
40 |
Correct |
3 ms |
1868 KB |
Output is correct |
41 |
Correct |
3 ms |
1868 KB |
Output is correct |
42 |
Correct |
3 ms |
1868 KB |
Output is correct |
43 |
Correct |
3 ms |
1868 KB |
Output is correct |
44 |
Correct |
3 ms |
1868 KB |
Output is correct |
45 |
Correct |
3 ms |
1904 KB |
Output is correct |
46 |
Correct |
2 ms |
2052 KB |
Output is correct |
47 |
Correct |
2 ms |
1868 KB |
Output is correct |
48 |
Correct |
3 ms |
1868 KB |
Output is correct |
49 |
Correct |
3 ms |
1868 KB |
Output is correct |
50 |
Correct |
3 ms |
1940 KB |
Output is correct |
51 |
Correct |
3 ms |
1996 KB |
Output is correct |
52 |
Correct |
148 ms |
8156 KB |
Output is correct |
53 |
Correct |
115 ms |
14008 KB |
Output is correct |
54 |
Correct |
150 ms |
13168 KB |
Output is correct |
55 |
Correct |
148 ms |
13316 KB |
Output is correct |
56 |
Correct |
147 ms |
13616 KB |
Output is correct |
57 |
Correct |
142 ms |
13348 KB |
Output is correct |
58 |
Correct |
149 ms |
13888 KB |
Output is correct |
59 |
Correct |
145 ms |
13448 KB |
Output is correct |
60 |
Correct |
137 ms |
13104 KB |
Output is correct |
61 |
Correct |
146 ms |
13304 KB |
Output is correct |
62 |
Correct |
144 ms |
13364 KB |
Output is correct |
63 |
Correct |
109 ms |
20828 KB |
Output is correct |
64 |
Correct |
109 ms |
14076 KB |
Output is correct |
65 |
Correct |
116 ms |
14012 KB |
Output is correct |
66 |
Correct |
120 ms |
13908 KB |
Output is correct |
67 |
Correct |
114 ms |
14120 KB |
Output is correct |
68 |
Correct |
112 ms |
14024 KB |
Output is correct |
69 |
Correct |
147 ms |
13704 KB |
Output is correct |
70 |
Correct |
148 ms |
13776 KB |
Output is correct |
71 |
Correct |
147 ms |
13744 KB |
Output is correct |
72 |
Correct |
155 ms |
13732 KB |
Output is correct |
73 |
Correct |
157 ms |
13744 KB |
Output is correct |
74 |
Correct |
153 ms |
13828 KB |
Output is correct |
75 |
Correct |
147 ms |
13860 KB |
Output is correct |
76 |
Correct |
153 ms |
13868 KB |
Output is correct |
77 |
Correct |
152 ms |
13732 KB |
Output is correct |
78 |
Correct |
156 ms |
13892 KB |
Output is correct |
79 |
Correct |
148 ms |
13328 KB |
Output is correct |
80 |
Correct |
147 ms |
13360 KB |
Output is correct |