Submission #717762

# Submission time Handle Problem Language Result Execution time Memory
717762 2023-04-02T13:08:17 Z Toxtaq Art Exhibition (JOI18_art) C++17
100 / 100
252 ms 95960 KB
#include<bits/stdc++.h>
using namespace std;
vector<int>LOG;
struct SparseTable{
    vector<vector<long long>>sTable;
    SparseTable(int n, vector<long long>&v){
        sTable.resize(LOG[n] + 1);
        for(int i = 0;i <= LOG[n];++i)sTable[i].resize(n + 1);
        for(int i = 1;i <= n;++i){
            sTable[0][i] = v[i];
        }
        for(int i = 1;i <= LOG[n];++i){
            for(int j = 1;j + (1 << (i - 1)) <= n;++j){
                sTable[i][j] = max(sTable[i - 1][j], sTable[i - 1][j + (1 << (i - 1))]);
            }
        }
    }
    long long Query(int l, int r){
        int lg = LOG[r - l + 1];
        return max(sTable[lg][l], sTable[lg][r - (1 << lg) + 1]);
    }
};
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    LOG.resize(n + 1);
    LOG[1] = 0;
    for(int i = 2;i <= n;++i)LOG[i] = LOG[i / 2] + 1;
    vector<pair<long long, long long>>arts(n + 1);
    for(int i = 1;i <= n;++i){
        cin >> arts[i].first >> arts[i].second;
    }
    sort(arts.begin(), arts.end());
    vector<long long>P(n + 1);
    for(int i = 1;i <= n;++i){
        P[i] = P[i - 1] + arts[i].second + arts[i - 1].first - arts[i].first;
//        cout << "P[" << i << "]=" << P[i] << '\n';
    }
    SparseTable table(n, P);
    long long mx = 0;
    for(int i = 1;i <= n;++i){
        long long P_max = table.Query(i, n);
        long long num = (P_max - P[i - 1]) - arts[i - 1].first + arts[i].first;
        mx = max(mx, num);
    }
    cout << mx;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 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 0 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 0 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 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 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 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 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 0 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 0 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 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 852 KB Output is correct
28 Correct 3 ms 852 KB Output is correct
29 Correct 2 ms 852 KB Output is correct
30 Correct 2 ms 852 KB Output is correct
31 Correct 2 ms 852 KB Output is correct
32 Correct 2 ms 852 KB Output is correct
33 Correct 2 ms 852 KB Output is correct
34 Correct 3 ms 852 KB Output is correct
35 Correct 3 ms 852 KB Output is correct
36 Correct 2 ms 852 KB Output is correct
37 Correct 2 ms 852 KB Output is correct
38 Correct 3 ms 852 KB Output is correct
39 Correct 4 ms 852 KB Output is correct
40 Correct 3 ms 852 KB Output is correct
41 Correct 2 ms 928 KB Output is correct
42 Correct 2 ms 852 KB Output is correct
43 Correct 2 ms 852 KB Output is correct
44 Correct 2 ms 852 KB Output is correct
45 Correct 2 ms 852 KB Output is correct
46 Correct 2 ms 852 KB Output is correct
47 Correct 3 ms 928 KB Output is correct
48 Correct 2 ms 852 KB Output is correct
49 Correct 3 ms 852 KB Output is correct
50 Correct 2 ms 852 KB Output is correct
51 Correct 2 ms 920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 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 0 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 0 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 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 852 KB Output is correct
28 Correct 3 ms 852 KB Output is correct
29 Correct 2 ms 852 KB Output is correct
30 Correct 2 ms 852 KB Output is correct
31 Correct 2 ms 852 KB Output is correct
32 Correct 2 ms 852 KB Output is correct
33 Correct 2 ms 852 KB Output is correct
34 Correct 3 ms 852 KB Output is correct
35 Correct 3 ms 852 KB Output is correct
36 Correct 2 ms 852 KB Output is correct
37 Correct 2 ms 852 KB Output is correct
38 Correct 3 ms 852 KB Output is correct
39 Correct 4 ms 852 KB Output is correct
40 Correct 3 ms 852 KB Output is correct
41 Correct 2 ms 928 KB Output is correct
42 Correct 2 ms 852 KB Output is correct
43 Correct 2 ms 852 KB Output is correct
44 Correct 2 ms 852 KB Output is correct
45 Correct 2 ms 852 KB Output is correct
46 Correct 2 ms 852 KB Output is correct
47 Correct 3 ms 928 KB Output is correct
48 Correct 2 ms 852 KB Output is correct
49 Correct 3 ms 852 KB Output is correct
50 Correct 2 ms 852 KB Output is correct
51 Correct 2 ms 920 KB Output is correct
52 Correct 203 ms 88312 KB Output is correct
53 Correct 234 ms 95816 KB Output is correct
54 Correct 224 ms 95888 KB Output is correct
55 Correct 252 ms 95800 KB Output is correct
56 Correct 217 ms 95868 KB Output is correct
57 Correct 243 ms 95860 KB Output is correct
58 Correct 224 ms 95904 KB Output is correct
59 Correct 227 ms 95796 KB Output is correct
60 Correct 227 ms 95804 KB Output is correct
61 Correct 214 ms 95760 KB Output is correct
62 Correct 224 ms 95864 KB Output is correct
63 Correct 215 ms 95776 KB Output is correct
64 Correct 222 ms 95800 KB Output is correct
65 Correct 228 ms 95860 KB Output is correct
66 Correct 229 ms 95788 KB Output is correct
67 Correct 236 ms 95960 KB Output is correct
68 Correct 225 ms 95840 KB Output is correct