Submission #875947

# Submission time Handle Problem Language Result Execution time Memory
875947 2023-11-20T20:26:15 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;
}

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

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

    int 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]);
}

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

    int 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);
}

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

    build(1, 1, n);

    long long maxim = LLONG_MIN;
    for (int 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 'int query(int, int, int, int, 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:56:23: error: 'LLONG_MIN' was not declared in this scope
   56 |     long long maxim = LLONG_MIN;
      |                       ^~~~~~~~~
art.cpp:56:23: note: 'LLONG_MIN' is defined in header '<climits>'; did you forget to '#include <climits>'?