File tree 1 file changed +45
-0
lines changed 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+
3
+ using namespace std ;
4
+ using ll = long long ;
5
+
6
+ int N, A, B;
7
+ vector<int > X;
8
+
9
+ ll solve () {
10
+ vector<vector<int >> es;
11
+ for (int i = 1 ; i < N; ++i) {
12
+ int w = X[i] - X[i-1 ];
13
+ es.push_back ({ w, i - 1 , i });
14
+ }
15
+
16
+ vector<bool > has_next (N, false );
17
+ ll ans = 0 ;
18
+ sort (es.begin (), es.end ());
19
+ for (auto const & e : es) {
20
+ ll w = e[0 ];
21
+ int u = e[1 ];
22
+ if (w * A >= B) continue ;
23
+ ans += w * A;
24
+ has_next[u] = true ;
25
+ }
26
+ for (int i = 0 ; i < N - 1 ; ++i) {
27
+ if (has_next[i]) continue ;
28
+ ans += B;
29
+ }
30
+ return ans;
31
+ }
32
+
33
+ int main () {
34
+ ios_base::sync_with_stdio (false );
35
+ cin.tie (0 ); cout.tie (0 );
36
+
37
+ cin >> N >> A >> B;
38
+ X.assign (N, 0 );
39
+ for (int i = 0 ; i < N; ++i) {
40
+ cin >> X[i];
41
+ }
42
+ cout << solve () << endl;
43
+
44
+ return 0 ;
45
+ }
You can’t perform that action at this time.
0 commit comments