Skip to content

Commit 04905ae

Browse files
committed
atcoder/abc052D (feedback from editorial)
1 parent f6e3dc2 commit 04905ae

File tree

1 file changed

+3
-18
lines changed

1 file changed

+3
-18
lines changed

atcoder/abc052/D/main.cpp

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,10 @@ int N, A, B;
77
vector<int> X;
88

99
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);
1710
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;
11+
for (int i = 1; i < N; ++i) {
12+
ll w = X[i] - X[i-1];
13+
ans += min(w * A, ll(B));
2914
}
3015
return ans;
3116
}

0 commit comments

Comments
 (0)