Submission #875951

# Submission time Handle Problem Language Result Execution time Memory
875951 2023-11-20T20:44:25 Z misu2005 Art Exhibition (JOI18_art) C++11
Compilation error
0 ms 0 KB
#include <iostream>
#include <algorithm>

using namespace std;

struct ceva {
    long long sz, val;
} v[500002];

bool cmp(ceva x, ceva y) {
    return x.sz < y.sz;
}

long long n;
long long sp[500002], tree[2000005];

void build(long long node, long long st, long long dr) {
    if (st == dr) {
        tree[node] = sp[st] - v[st].sz;
        return ;
    }

    long long mij = (st + dr)/2;
    build(2*node, st, mij);
    build(2*node+1, mij+1, dr);
    tree[node] = max(tree[2*node], tree[2*node+1]);
}

long long query(long long node, long long st, long long dr, long long left, long long right) {
    if (left <= st and dr <= right) {
        return tree[node];
    }

    long long mij = (st + dr)/2;
    long long ans1 = LLONG_MIN, ans2 = LLONG_MIN;
    if (left <= mij)
        ans1 = query(2*node, st, mij, left, right);
    if (mij < right)
        ans2 = query(2*node+1, mij+1, dr, left, right);
    return max(ans1, ans2);
}

signed main()
{
    cin >> n;
    for (long long i = 1; i <= n; i++) {
        cin >> v[i].sz >> v[i].val;
    }
    sort(v+1, v+n+1, cmp);
    for (long long i = 1; i <= n; i++) {
        sp[i] = sp[i-1] + v[i].val;
    }

//    for (long long i = 1; i <= n; i++) {
//        cout << sp[i]-v[i].sz << endl;
//    }
//    return 0;

    build(1, 1, n);

//    for (long longi = 1; i <= 4*n; i++) {
//        cout << i << " " << tree[i] << endl;
//    }
//
//    cout << query(1, 1, n, 5, 6);

    long long maxim = LLONG_MIN;
    for (long long i = 1; i <= n; i++) {
        long long  x = sp[i-1] - v[i].sz;
        long long rezdr = query(1, 1, n, i, n);
        maxim = max(maxim, rezdr-x);
    }
    cout << maxim;
    return 0;
}

Compilation message

art.cpp: In function 'long long int query(long long int, long long int, long long int, long long int, long long int)':
art.cpp:35:22: error: 'LLONG_MIN' was not declared in this scope
   35 |     long long ans1 = LLONG_MIN, ans2 = LLONG_MIN;
      |                      ^~~~~~~~~
art.cpp:3:1: note: 'LLONG_MIN' is defined in header '<climits>'; did you forget to '#include <climits>'?
    2 | #include <algorithm>
  +++ |+#include <climits>
    3 | 
art.cpp:39:9: error: 'ans2' was not declared in this scope; did you mean 'ans1'?
   39 |         ans2 = query(2*node+1, mij+1, dr, left, right);
      |         ^~~~
      |         ans1
art.cpp:40:22: error: 'ans2' was not declared in this scope; did you mean 'ans1'?
   40 |     return max(ans1, ans2);
      |                      ^~~~
      |                      ans1
art.cpp: In function 'int main()':
art.cpp:67:23: error: 'LLONG_MIN' was not declared in this scope
   67 |     long long maxim = LLONG_MIN;
      |                       ^~~~~~~~~
art.cpp:67:23: note: 'LLONG_MIN' is defined in header '<climits>'; did you forget to '#include <climits>'?