Submission #670679

# Submission time Handle Problem Language Result Execution time Memory
670679 2022-12-09T20:39:17 Z birthdaycake Art Exhibition (JOI18_art) C++17
100 / 100
424 ms 44416 KB
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
 
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
 
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
 

#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define int long long
using namespace std;
pair<int,int> a[500001],b[500001];
int seg[1<<20][2];
int N,Left,Right,W;

void Update(int Pos, int V){
    int ind = Pos + N - 1;
    seg[ind][W] = V;
    while(ind /= 2) seg[ind][W] = max(seg[ind * 2][W], seg[ind * 2 + 1][W]);
}

int Query(int l = 1, int r = N, int ind = 1){
    if(l > Right or r < Left) return -1e18;
    if(l >= Left && r <= Right) return seg[ind][W];
    int mid = (l + r) / 2;
    return max(Query(l, mid, ind * 2), Query(mid + 1, r, ind * 2 + 1));
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, ans = 0; cin >> n;
    N = exp2(ceil(log2(n)));
    for(int i = 0; i < n; i++){
        cin >> a[i].first >> a[i].second;
        ans = max(ans, a[i].second);
    }
    sort(a,a+n);
    for(int i = 0; i < n; i++){
        if(i) a[i].second += a[i - 1].second;
        b[i].first = a[i].second - a[i].first;
        b[i].second = (i == 0 ? 0 : -a[i - 1].second) + a[i].first;
        W = 0;
        Update(i + 1, b[i].first);
        W = 1;
        Update(i + 1, b[i].second);
    }
    for(int i = 0; i < n; i++){
        Left = 1; Right = i;
        W = 1;
        ans = max(ans, b[i].first + Query());
        Left = i + 2; Right = n;
        W = 0;
        ans = max(ans, b[i].second + Query());
    }
    cout << ans;
    return 0;
}
/*
 
 */
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 244 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 244 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 4 ms 788 KB Output is correct
28 Correct 4 ms 724 KB Output is correct
29 Correct 4 ms 724 KB Output is correct
30 Correct 4 ms 724 KB Output is correct
31 Correct 5 ms 804 KB Output is correct
32 Correct 4 ms 724 KB Output is correct
33 Correct 4 ms 724 KB Output is correct
34 Correct 4 ms 724 KB Output is correct
35 Correct 3 ms 724 KB Output is correct
36 Correct 4 ms 724 KB Output is correct
37 Correct 4 ms 724 KB Output is correct
38 Correct 4 ms 784 KB Output is correct
39 Correct 4 ms 724 KB Output is correct
40 Correct 4 ms 724 KB Output is correct
41 Correct 4 ms 776 KB Output is correct
42 Correct 4 ms 724 KB Output is correct
43 Correct 4 ms 724 KB Output is correct
44 Correct 3 ms 724 KB Output is correct
45 Correct 4 ms 724 KB Output is correct
46 Correct 5 ms 724 KB Output is correct
47 Correct 5 ms 804 KB Output is correct
48 Correct 4 ms 724 KB Output is correct
49 Correct 5 ms 724 KB Output is correct
50 Correct 4 ms 704 KB Output is correct
51 Correct 3 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 244 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 4 ms 788 KB Output is correct
28 Correct 4 ms 724 KB Output is correct
29 Correct 4 ms 724 KB Output is correct
30 Correct 4 ms 724 KB Output is correct
31 Correct 5 ms 804 KB Output is correct
32 Correct 4 ms 724 KB Output is correct
33 Correct 4 ms 724 KB Output is correct
34 Correct 4 ms 724 KB Output is correct
35 Correct 3 ms 724 KB Output is correct
36 Correct 4 ms 724 KB Output is correct
37 Correct 4 ms 724 KB Output is correct
38 Correct 4 ms 784 KB Output is correct
39 Correct 4 ms 724 KB Output is correct
40 Correct 4 ms 724 KB Output is correct
41 Correct 4 ms 776 KB Output is correct
42 Correct 4 ms 724 KB Output is correct
43 Correct 4 ms 724 KB Output is correct
44 Correct 3 ms 724 KB Output is correct
45 Correct 4 ms 724 KB Output is correct
46 Correct 5 ms 724 KB Output is correct
47 Correct 5 ms 804 KB Output is correct
48 Correct 4 ms 724 KB Output is correct
49 Correct 5 ms 724 KB Output is correct
50 Correct 4 ms 704 KB Output is correct
51 Correct 3 ms 724 KB Output is correct
52 Correct 372 ms 44224 KB Output is correct
53 Correct 377 ms 44388 KB Output is correct
54 Correct 378 ms 44208 KB Output is correct
55 Correct 378 ms 44236 KB Output is correct
56 Correct 385 ms 44400 KB Output is correct
57 Correct 424 ms 44236 KB Output is correct
58 Correct 390 ms 44236 KB Output is correct
59 Correct 373 ms 44232 KB Output is correct
60 Correct 376 ms 44416 KB Output is correct
61 Correct 369 ms 44116 KB Output is correct
62 Correct 372 ms 44164 KB Output is correct
63 Correct 367 ms 44260 KB Output is correct
64 Correct 368 ms 44228 KB Output is correct
65 Correct 374 ms 44348 KB Output is correct
66 Correct 366 ms 44196 KB Output is correct
67 Correct 383 ms 44376 KB Output is correct
68 Correct 377 ms 44228 KB Output is correct