-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirecrackers.cpp
More file actions
52 lines (38 loc) · 987 Bytes
/
firecrackers.cpp
File metadata and controls
52 lines (38 loc) · 987 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
47
48
49
50
51
52
// https://dunjudge.me/analysis/problems/1811/
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int main ()
{
int n;
cin >> n;
vector<pair<int, int>> fc (n);
for (int i = 0; i < n; ++i) {
cin >> fc[i].first >> fc[i].second;
}
for (int i = 0; i < fc.size(); ++i) {
cout << fc[i].first << " " << fc[i].second << endl;
}
sort(fc.begin(), fc.end());
vector<int> dp(n, 0);
dp[0] = fc[0].second;
int fuse = fc[0].first;
int maxim = -2;
int pos = -1;
for (int i = 1; i < n; ++i) {
dp[i] = dp[i-1] + fc[i].second - (i*(abs(fc[i].first-fuse)));
fuse = fc[i].first;
if (maxim <= dp[i]) {
maxim = dp[i];
pos = i;
}
}
for (int i = 0; i <= pos; ++i) {
int curr = fc[i].second - fc[pos].first + fc[i].first;
if (curr < 0) {
maxim = maxim + abs(curr);
}
}
cout << maxim << "\n";
}