Submission #231249

# Submission time Handle Problem Language Result Execution time Memory
231249 2020-05-13T07:31:23 Z SorahISA Art Exhibition (JOI18_art) C++17
100 / 100
247 ms 36580 KB
// #pragma GCC target("avx2")
#pragma GCC optimize("O3", "unroll-loops")

// #include <bits/extc++.h>
// using namespace __gnu_pbds;

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define double long double
// template <typename T>
// using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using pii = pair<int, int>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using Prior = priority_queue<T>;

#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back

#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define RANDOM() random_device __rd; \
                 mt19937 __gen = mt19937(__rd()); \
                 uniform_int_distribution<int> __dis(0, 1); \
                 auto rnd = bind(__dis, __gen);

const int INF = 1E18;
const int mod = 1E9 + 7;

int32_t main() {
    fastIO();
    
    int n, tot = 0;
    cin >> n;
    
    vector<pii> v(n), art;
    for (auto &[a, b] : v) cin >> a >> b, tot += b;
    sort(ALL(v));
    
    art.eb(v[0]);
    for (int i = 1; i < n; ++i) {
        if (v[i].X == v[i-1].X) art.back().Y += v[i].Y;
        else art.eb(v[i]);
    }
    tot -= art.back().X - art.front().X;
    
    n = art.size();
    vector<int> pre(n+2), suf(n+2);
    for (int i = 1; i < n; ++i) {
        pre[i] = pre[i-1] + (art[i].X - art[i-1].X) - art[i-1].Y;
    }
    for (int i = n; i > 1; --i) {
        suf[i] = suf[i+1] + (art[i-1].X - art[i-2].X) - art[i-1].Y;
    }
    
    // for (auto x : pre) cout << x << " "; cout << "\n";
    // for (auto x : suf) cout << x << " "; cout << "\n";
    
    for (int i = 1; i < n; ++i) pre[i] = max(pre[i], pre[i-1]);
    for (int i = n; i > 1; --i) suf[i] = max(suf[i], suf[i+1]);
    
    int maxDeleted = 0;
    for (int i = 1; i < n; ++i) maxDeleted = max(maxDeleted, pre[i] + suf[i+2]);
    
    cout << tot + maxDeleted << "\n";
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 8 ms 768 KB Output is correct
28 Correct 7 ms 768 KB Output is correct
29 Correct 7 ms 768 KB Output is correct
30 Correct 7 ms 768 KB Output is correct
31 Correct 7 ms 768 KB Output is correct
32 Correct 8 ms 768 KB Output is correct
33 Correct 8 ms 768 KB Output is correct
34 Correct 7 ms 768 KB Output is correct
35 Correct 7 ms 768 KB Output is correct
36 Correct 7 ms 816 KB Output is correct
37 Correct 6 ms 768 KB Output is correct
38 Correct 7 ms 768 KB Output is correct
39 Correct 6 ms 768 KB Output is correct
40 Correct 7 ms 768 KB Output is correct
41 Correct 6 ms 768 KB Output is correct
42 Correct 7 ms 768 KB Output is correct
43 Correct 7 ms 768 KB Output is correct
44 Correct 7 ms 768 KB Output is correct
45 Correct 7 ms 768 KB Output is correct
46 Correct 7 ms 768 KB Output is correct
47 Correct 7 ms 768 KB Output is correct
48 Correct 7 ms 768 KB Output is correct
49 Correct 7 ms 768 KB Output is correct
50 Correct 7 ms 768 KB Output is correct
51 Correct 7 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 8 ms 768 KB Output is correct
28 Correct 7 ms 768 KB Output is correct
29 Correct 7 ms 768 KB Output is correct
30 Correct 7 ms 768 KB Output is correct
31 Correct 7 ms 768 KB Output is correct
32 Correct 8 ms 768 KB Output is correct
33 Correct 8 ms 768 KB Output is correct
34 Correct 7 ms 768 KB Output is correct
35 Correct 7 ms 768 KB Output is correct
36 Correct 7 ms 816 KB Output is correct
37 Correct 6 ms 768 KB Output is correct
38 Correct 7 ms 768 KB Output is correct
39 Correct 6 ms 768 KB Output is correct
40 Correct 7 ms 768 KB Output is correct
41 Correct 6 ms 768 KB Output is correct
42 Correct 7 ms 768 KB Output is correct
43 Correct 7 ms 768 KB Output is correct
44 Correct 7 ms 768 KB Output is correct
45 Correct 7 ms 768 KB Output is correct
46 Correct 7 ms 768 KB Output is correct
47 Correct 7 ms 768 KB Output is correct
48 Correct 7 ms 768 KB Output is correct
49 Correct 7 ms 768 KB Output is correct
50 Correct 7 ms 768 KB Output is correct
51 Correct 7 ms 768 KB Output is correct
52 Correct 239 ms 36452 KB Output is correct
53 Correct 238 ms 36580 KB Output is correct
54 Correct 233 ms 36428 KB Output is correct
55 Correct 232 ms 36580 KB Output is correct
56 Correct 223 ms 36452 KB Output is correct
57 Correct 227 ms 36456 KB Output is correct
58 Correct 242 ms 36580 KB Output is correct
59 Correct 225 ms 36452 KB Output is correct
60 Correct 229 ms 36452 KB Output is correct
61 Correct 231 ms 36452 KB Output is correct
62 Correct 228 ms 36452 KB Output is correct
63 Correct 237 ms 36452 KB Output is correct
64 Correct 237 ms 36452 KB Output is correct
65 Correct 225 ms 36452 KB Output is correct
66 Correct 225 ms 36452 KB Output is correct
67 Correct 240 ms 36452 KB Output is correct
68 Correct 247 ms 36452 KB Output is correct