-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcf38e.cpp
More file actions
46 lines (39 loc) · 816 Bytes
/
cf38e.cpp
File metadata and controls
46 lines (39 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
const int MAX_N = 3007;
typedef long long ll;
struct Node {
int x, c;
Node() {
}
Node(int i, int j) {
x = i, c = j;
}
bool operator < (const Node &rhs) const {
return x < rhs.x || (x == rhs.x && c < rhs.c);
}
};
int n;
Node marble[MAX_N];
ll dp[MAX_N];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d%d", &marble[i].x, &marble[i].c);
}
sort(marble + 1, marble + 1 + n);
dp[1] = marble[1].c;
for (int i = 2; i <= n; ++i) {
ll cost = 0;
dp[i] = dp[i - 1] + marble[i].c;
for (int j = i - 1; j >= 1; --j) {
cost += (ll)abs(marble[j].x - marble[j + 1].x) * (i - j);
dp[i] = min(dp[i], dp[j - 1] + marble[j].c + cost);
}
}
printf("%lld\n", dp[n]);
return 0;
}