// 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];
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++){
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);
for(int j = 0; j < i; j++)
dp[i] = min(dp[i], dp[j] + (D[i].S - D[j].S) + (i - j) * 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 |
2 ms |
1852 KB |
Output is correct |
3 |
Correct |
2 ms |
1868 KB |
Output is correct |
4 |
Correct |
2 ms |
1868 KB |
Output is correct |
5 |
Correct |
2 ms |
1868 KB |
Output is correct |
6 |
Correct |
2 ms |
1868 KB |
Output is correct |
7 |
Correct |
2 ms |
1868 KB |
Output is correct |
8 |
Correct |
2 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 |
2 ms |
1868 KB |
Output is correct |
12 |
Correct |
3 ms |
1868 KB |
Output is correct |
13 |
Correct |
2 ms |
1868 KB |
Output is correct |
14 |
Correct |
2 ms |
1856 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 |
1856 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 |
2 ms |
1852 KB |
Output is correct |
3 |
Correct |
2 ms |
1868 KB |
Output is correct |
4 |
Correct |
2 ms |
1868 KB |
Output is correct |
5 |
Correct |
2 ms |
1868 KB |
Output is correct |
6 |
Correct |
2 ms |
1868 KB |
Output is correct |
7 |
Correct |
2 ms |
1868 KB |
Output is correct |
8 |
Correct |
2 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 |
2 ms |
1868 KB |
Output is correct |
12 |
Correct |
3 ms |
1868 KB |
Output is correct |
13 |
Correct |
2 ms |
1868 KB |
Output is correct |
14 |
Correct |
2 ms |
1856 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 |
1856 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 |
2 ms |
1868 KB |
Output is correct |
26 |
Correct |
2 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 |
1860 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 |
6 ms |
1860 KB |
Output is correct |
36 |
Correct |
2 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 |
2 ms |
1852 KB |
Output is correct |
3 |
Correct |
2 ms |
1868 KB |
Output is correct |
4 |
Correct |
2 ms |
1868 KB |
Output is correct |
5 |
Correct |
2 ms |
1868 KB |
Output is correct |
6 |
Correct |
2 ms |
1868 KB |
Output is correct |
7 |
Correct |
2 ms |
1868 KB |
Output is correct |
8 |
Correct |
2 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 |
2 ms |
1868 KB |
Output is correct |
12 |
Correct |
3 ms |
1868 KB |
Output is correct |
13 |
Correct |
2 ms |
1868 KB |
Output is correct |
14 |
Correct |
2 ms |
1856 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 |
1856 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 |
2 ms |
1868 KB |
Output is correct |
26 |
Correct |
2 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 |
1860 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 |
6 ms |
1860 KB |
Output is correct |
36 |
Correct |
2 ms |
1868 KB |
Output is correct |
37 |
Correct |
2 ms |
1868 KB |
Output is correct |
38 |
Correct |
7 ms |
2000 KB |
Output is correct |
39 |
Correct |
5 ms |
1996 KB |
Output is correct |
40 |
Correct |
5 ms |
1996 KB |
Output is correct |
41 |
Correct |
4 ms |
2032 KB |
Output is correct |
42 |
Correct |
4 ms |
1996 KB |
Output is correct |
43 |
Correct |
4 ms |
1996 KB |
Output is correct |
44 |
Correct |
4 ms |
1996 KB |
Output is correct |
45 |
Correct |
4 ms |
1996 KB |
Output is correct |
46 |
Correct |
5 ms |
2000 KB |
Output is correct |
47 |
Correct |
5 ms |
1996 KB |
Output is correct |
48 |
Correct |
4 ms |
1996 KB |
Output is correct |
49 |
Correct |
4 ms |
2024 KB |
Output is correct |
50 |
Correct |
4 ms |
1996 KB |
Output is correct |
51 |
Correct |
4 ms |
1996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1868 KB |
Output is correct |
2 |
Correct |
2 ms |
1852 KB |
Output is correct |
3 |
Correct |
2 ms |
1868 KB |
Output is correct |
4 |
Correct |
2 ms |
1868 KB |
Output is correct |
5 |
Correct |
2 ms |
1868 KB |
Output is correct |
6 |
Correct |
2 ms |
1868 KB |
Output is correct |
7 |
Correct |
2 ms |
1868 KB |
Output is correct |
8 |
Correct |
2 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 |
2 ms |
1868 KB |
Output is correct |
12 |
Correct |
3 ms |
1868 KB |
Output is correct |
13 |
Correct |
2 ms |
1868 KB |
Output is correct |
14 |
Correct |
2 ms |
1856 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 |
1856 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 |
2 ms |
1868 KB |
Output is correct |
26 |
Correct |
2 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 |
1860 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 |
6 ms |
1860 KB |
Output is correct |
36 |
Correct |
2 ms |
1868 KB |
Output is correct |
37 |
Correct |
2 ms |
1868 KB |
Output is correct |
38 |
Correct |
7 ms |
2000 KB |
Output is correct |
39 |
Correct |
5 ms |
1996 KB |
Output is correct |
40 |
Correct |
5 ms |
1996 KB |
Output is correct |
41 |
Correct |
4 ms |
2032 KB |
Output is correct |
42 |
Correct |
4 ms |
1996 KB |
Output is correct |
43 |
Correct |
4 ms |
1996 KB |
Output is correct |
44 |
Correct |
4 ms |
1996 KB |
Output is correct |
45 |
Correct |
4 ms |
1996 KB |
Output is correct |
46 |
Correct |
5 ms |
2000 KB |
Output is correct |
47 |
Correct |
5 ms |
1996 KB |
Output is correct |
48 |
Correct |
4 ms |
1996 KB |
Output is correct |
49 |
Correct |
4 ms |
2024 KB |
Output is correct |
50 |
Correct |
4 ms |
1996 KB |
Output is correct |
51 |
Correct |
4 ms |
1996 KB |
Output is correct |
52 |
Execution timed out |
2052 ms |
13072 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |